import React, { useState } from 'react'; import createClass from 'create-react-class'; import { Meta, Story } from '@storybook/react'; import PropTypes from 'prop-types'; import Portal, { IPortalProps } from './Portal'; import Button from '../Button/Button'; export default { title: 'Utility/Portal', component: Portal, parameters: { docs: { description: { component: Portal.peek.description, }, }, }, } as Meta; /* Basic */ export const Basic: Story = (args) => { const [state, setState] = useState({ left: 216, top: 460, }); const handleClick = (event) => { const { height, width } = event.target.getBoundingClientRect(); setState({ left: event.pageX - width / 2, top: event.pageY - height / 2, }); }; const { left, top } = state; return (

click to move

({left}, {top})

inspect me

); }; /* Context */ export const Context: Story = () => { const context: any = React.createContext({ display: 'hello', }); class ExampleApp extends React.Component { static propTypes: { children: PropTypes.Requireable; }; constructor(props: any) { super(props); this.state = { counter: 0, increment: () => { this.setState(({ counter }: any) => ({ counter: counter + 1 })); }, }; } render() { return ( {this.props.children} ); } } ExampleApp.propTypes = { children: PropTypes.node, }; const Component = createClass({ render() { return ( {({ counter, increment }: any) => (

counter: {counter}

)}
{({ counter, increment }: any) => (
inside the portal counter: {counter}
)}
); }, }); return ; };