How to use the @storybook/addons.useState function in @storybook/addons

To help you get started, we’ve selected a few @storybook/addons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github influxdata / clockface / src / Components / Inputs / Documentation / Inputs.stories.tsx View on Github external
() => {
    const toggleRef: RefObject = createRef()
    const toggleContainerRef: RefObject = createRef()

    const [checked, setChecked] = useState(false)

    const handleToggleChange = (): void => {
      setChecked(!checked)
    }

    const handleLogRefs = (): void => {
      /* eslint-disable */
      console.log('ToggleRef', toggleRef.current)
      console.log('ToggleContainerRef', toggleContainerRef.current)
      /* eslint-enable */
    }

    return (
      <div>
        </div>
github influxdata / clockface / src / Components / Inputs / Documentation / Inputs.stories.tsx View on Github external
() =&gt; {
    const [rangeSliderValue, setRangeSliderValue] = useState(50)
    const rangeSliderRef: RefObject = createRef()

    const handleInputChange = (e: ChangeEvent): void =&gt; {
      setRangeSliderValue(parseInt(e.target.value))
    }

    const handleLogRef = (): void =&gt; {
      /* eslint-disable */
      console.log(rangeSliderRef.current)
      /* eslint-enable */
    }

    const exampleRangeSliderStyle = {width: '100%'}

    return (
      <div></div>
github storybookjs / storybook / addons / live-edit / src / withEditor.tsx View on Github external
export function withEditor(storyFn: any) {
  const [state, setState] = useState('');
  const scope = useParameter('scope');
  const liveEditConfig: LiveEditConfiguration | undefined = useParameter('live-edit');
  const scopeComponents =
    liveEditConfig && liveEditConfig.components ? liveEditConfig.components : {};

  useChannel({
    [EVENT_NEW_SOURCE]: s => {
      setState(s);
    },
  });

  if (state) {
    try {
      return scopeEval(transform(state, { presets: [['react']] }).code, {
        // @ts-ignore
        ...scope,
github influxdata / clockface / src / Components / Inputs / Documentation / Inputs.stories.tsx View on Github external
() =&gt; {
    const [value, setValue] = useState(25)

    return (
      <div>
        <input value="{value}" max="{number('max'," min="{number('min',">
            setValue(e.target.value === '' ? NaN : Number(e.target.value))
          }
          name={text('name', 'Name')}
          titleText={text('titleText', 'Title Text')}
          disabledTitleText={text('disabledTitleText', 'Disabled Title Text')}
          maxLength={number('maxLength', 24)}
          icon={
            IconFont[</div>
github bbc / psammead / packages / components / psammead-navigation / src / index.stories.jsx View on Github external
const navigationStory = (currentPageText, navData, dir, brand, isAmp) =&gt; ({
  script,
  service,
}) =&gt; {
  const ScrollableNavigation = isAmp
    ? AmpScrollableNavigation
    : CanonicalScrollableNavigation;

  const [isScrollable, setIsScrollable] = useState(false);

  useEffect(() =&gt; {
    const mediaQueryList = window.matchMedia('(max-width: 37.5rem)');
    setIsScrollable(mediaQueryList.matches);

    const handler = event =&gt; setIsScrollable(event.matches);
    mediaQueryList.addListener(handler);

    return () =&gt; mediaQueryList.removeListener(handler);
  }, []);

  return (
    &lt;&gt;
      {brand &amp;&amp; getBrand()}
github influxdata / clockface / src / Components / DapperScrollbars / Documentation / DapperScrollbars.stories.tsx View on Github external
scrollbarStories.add('Scrollbar Example', () =&gt; {
  const [selection, setSelection] = useState('Foo')
  const handleSelectionChange = (value: string) =&gt; {
    setSelection(value)
  }

  return (
    <div>
      <div>
        </div></div>
github influxdata / clockface / src / Components / Inputs / Documentation / Inputs.stories.tsx View on Github external
() =&gt; {
    const [weapon, setWeapon] = useState('chainsaw')

    const handleToggleChange = (value: string): void =&gt; {
      setWeapon(value)
    }

    return (
      <div>
        
          <p>Choose a weapon to fight zombies with</p>
          </div>