moveable icon indicating copy to clipboard operation
moveable copied to clipboard

How to show buttons in pure javascript

Open JigarPrajpati opened this issue 2 years ago • 9 comments

Environments

  • Framework name:
  • Framework version:
  • Moveable Component version:
  • Testable Address(optional):

Description

https://daybrush.com/moveable/storybook/?path=/story/make-custom-able--editable-with-buttons

This is in react, we can't understand it please show us code in javascript plz. thank you

JigarPrajpati avatar Sep 15 '22 17:09 JigarPrajpati

@JigarPrajpati

You can use it by transpiling the react jsx code.

See https://codepen.io/daybrush/pen/JjXmbmb

Other frameworks / pure, vanilla demos are in preparation.

Let's try to make it possible to support the string method.

daybrush avatar Sep 18 '22 02:09 daybrush

Thank you so much for your support by heart, but this is for dimesion sample, i requried the button same like this image AND image

plz help me in pure javascript.

JigarPrajpati avatar Sep 18 '22 07:09 JigarPrajpati

@JigarPrajpati

  1. this is result of jsx transpile.
    const Editable = ({
        name: "editable",
        props: {}, events: {},
        render(moveable, Renderer) {
            const rect = moveable.getRect();
            const { pos2 } = moveable.state;
            const EditableViewer = moveable.useCSS("div", `
            {
                position: absolute;
                left: 0px;
                top: 0px;
                will-change: transform;
                transform-origin: 0px 0px;
            }
            .moveable-button {
                width: 24px;
                height: 24px;
                margin-bottom: 4px;
                background: #4af;
                border-radius: 4px;
                appearance: none;
                border: 0;
                color: white;
                font-weight: bold;
            }
            `);
            return Renderer.createElement(EditableViewer, {
                className: "moveable-editable",
                style: {
                    transform: `translate(${pos2[0]}px, ${pos2[1]}px) rotate(${rect.rotation}deg) translate(10px)`,
                }
            }, [
                Renderer.createElement("button", {
                    onClick: () => {
                        alert("+");
                    }
                }, [
                    "+"
                ]),
                Renderer.createElement("button", {
                    onClick: () => {
                        alert("-");
                    }
                }, [
                    "-"
                ]),
            ]);
        }
    });
  1. See https://codepen.io/daybrush/pen/JjXmbmb

daybrush avatar Sep 18 '22 09:09 daybrush

Dear sir i replaced the code you provided in codepan but it's not working sir. it's look like this. no button showing image

JigarPrajpati avatar Sep 23 '22 08:09 JigarPrajpati

@JigarPrajpati

No problem with the code. Check out this demo.

https://codepen.io/daybrush/pen/OJZxrzm

daybrush avatar Sep 24 '22 01:09 daybrush

Thank you sooo much by heart my dear bro!

  1. but i adding font awesome icon like trash, so how can i add that icon in button? image

  2. also can you let me know that these button how to show on top center? image

JigarPrajpati avatar Sep 24 '22 12:09 JigarPrajpati

@JigarPrajpati

  1. It can be used with syntax similar to React JSX. I used tagged-jsx and it would be easier to type <br/>. https://www.npmjs.com/package/tagged-jsx https://codepen.io/daybrush/pen/OJZxrzm?editors=1010

  2. Use CSS.

daybrush avatar Sep 25 '22 06:09 daybrush

Dear sir i understand, and it works completely fine, but i will need it at top location like this image

JigarPrajpati avatar Sep 26 '22 18:09 JigarPrajpati

@JigarPrajpati

You can get the position and size of the moveable through getRect.

The demo's editable position is on the right.

Calculate top, center through it.

https://daybrush.com/moveable/release/latest/doc/Moveable.html#.RectInfo

daybrush avatar Sep 28 '22 13:09 daybrush