@storybook/addon-actions#action JavaScript Examples

The following examples show how to use @storybook/addon-actions#action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockCheckGroup.stories.js    From pollen with MIT License 6 votes vote down vote up
Gallery = () => ({
  components: { BlockCheckGroup, TypeOverline },
  data() {
    return {
      options: [
        'Option 1',
        {
          label: 'My Second Option',
          description: 'My description text',
          value: 'foo',
        },
        {
          label: 'Option 3',
          description: 'My description text',
          value: 'bar',
        },
      ],
      value: ['foo'],
    };
  },
  methods: {
    handleInput: action('input'),
  },
  template: `
  <div>
    <div class="w-full sm:w-96">
      <BlockCheckGroup class="w-full" v-model="value" @input="handleInput" :options="options" vertical />
    </div>
  </div>
  `,
})
Example #2
Source File: Button.stories.js    From cypress-storybook with MIT License 6 votes vote down vote up
Text = () => {
  const [clicked, setClicked] = React.useState(false)

  return (
    <React.Fragment>
      <Button
        onClick={() => {
          action('click')('foo', 'bar')
          setClicked(true)
        }}
      >
        Hello Button
      </Button>
      <div id="knob">{text('text', 'Default Knob')}</div>
      <div id="clicked">{clicked ? 'clicked!' : ''}</div>
    </React.Fragment>
  )
}
Example #3
Source File: reduxDecorator.jsx    From simplQ-frontend with GNU General Public License v3.0 6 votes vote down vote up
reduxDecorator = (Story, context) => {
  const { state } = context.parameters;

  const store = configureStore({
    reducer: rootReducer,
    preloadedState: state,
  });

  store.dispatch = action('dispatch');

  const Decorator = () => {
    return (
      <Provider store={store}>
        <Story />
      </Provider>
    );
  };

  return <Decorator />;
}
Example #4
Source File: index.stories.js    From react-material-workspace-layout with MIT License 6 votes vote down vote up
Basic = () => (
  <Header
    leftSideContent="Left Side Content"
    onClickItem={action("onClickItem")}
    items={[
      { name: "Prev" },
      { name: "Next" },
      { name: "Clone", disabled: true },
      { name: "Settings" },
    ]}
  />
)
Example #5
Source File: buttons.js    From crate with MIT License 6 votes vote down vote up
// Buttons
storiesOf('Button', module)
  .add('primary', () => (
    <Button type="button" theme="primary" onClick={action('clicked')}>Button</Button>
  ))
  .add('secondary', () => (
    <Button type="button" theme="secondary" onClick={action('clicked')}>Button</Button>
  ))
  .add('default', () => (
    <Button type="button" onClick={action('clicked')}>Button</Button>
  ))
  .add('with icon', () => (
    <Button type="button" theme="primary" onClick={action('clicked')}>Button <Icon size={1.3}>face</Icon></Button>
  ))
Example #6
Source File: 1-EdlibModal.stories.js    From Edlib with GNU General Public License v3.0 6 votes vote down vote up
EdlibModal = () => {
    return (
        <AuthWrapper edlibApiUrl={edlibApiUrl}>
            {({ getJwt, getLanguage }) => {
                return (
                    <EdlibComponentsProvider
                        edlibUrl={edlibApiUrl}
                        getJwt={getJwt}
                        configuration={{
                            canReturnResources: true,
                        }}
                        language={getLanguage()}
                    >
                        <EdlibModalComponent
                            enableDoku={true}
                            enableVersionInterface={true}
                            onClose={action('on close')}
                            onResourceSelected={async (info) =>
                                action('Resource insert')(info)
                            }
                        />
                    </EdlibComponentsProvider>
                );
            }}
        </AuthWrapper>
    );
}
Example #7
Source File: Navbar.mobile.stories.js    From components with MIT License 6 votes vote down vote up
Navbar_On_Mobile = () => (
  <DefaultNavbar
    onClick={ action('clicked') }
    links={ links }
    logo={ defaultLogo }
    logoLink='https://default.services'
    logoTitle='Default Services'
  />
)
Example #8
Source File: alert.stories.js    From denali-ember with MIT License 6 votes vote down vote up
Playground = () => ({
  template: hbs`
    <DenaliAlert
      @title={{title}}
      @context={{context}}
      @style={{style}}
      @icon={{icon}}
      @isBlock={{isBlock}}
      @onClose={{onClose}}
      class={{class}}
    />
  `,
  context: {
    title: text('title', 'Denali Alert', argument),
    context: text('context', 'Optional alert details', argument),
    style: select('style', STYLES, STYLES[0], argument),
    icon: text('icon', 'stop-urgent', argument),
    isBlock: boolean('isBlock', false, argument),
    onClose: action('onClose'),
    class: text('class', '', attribute),
  },
})
Example #9
Source File: Message.stories.js    From kafka-java-vertx-starter with Apache License 2.0 6 votes vote down vote up
renderHelper = (
  Component,
  defaultErrorMessage,
  defaultIsFirst = false,
  defaultIsSelected = false,
  defaultMessagePartition = 0,
  defaultMessageOffset = 100,
  defaultMessageValue = 'Hello World!',
  defaultMessageTimestamp = new Date().getTime()
) => () => {
  const isFirst = boolean('First message', defaultIsFirst);
  const isSelected = boolean('Selected message', defaultIsSelected);
  const message = {
    topic: 'demo',
  };
  message.partition = number('Message partition', defaultMessagePartition);
  message.offset = number('Message offset', defaultMessageOffset);
  message.value = text('Message value', defaultMessageValue);
  message.timestamp = number('Message timestamp', defaultMessageTimestamp);

  const className = text('Custom CSS classname', undefined);
  const props = {
    isFirst,
    isSelected,
    message,
    className,
    onInteraction: action('handleClick'),
  };

  const errorMessage = text('Error message', defaultErrorMessage);
  if (errorMessage) {
    props.error = {
      message: errorMessage,
    };
  }

  return <Component {...props} />;
}
Example #10
Source File: ColorPicker.stories.js    From material-ui-color with MIT License 6 votes vote down vote up
Controller = ({ value }) => {
  const [color, setColor] = useState(value);
  const handleChange = newValue => {
    setColor(newValue);
    action('changed')(newValue);
  };
  return (
    <div style={{ display: 'flex', flexDirection: 'row' }}>
      <div>
        <div style={{ marginLeft: '-28px', marginTop: '-8px', paddingBottom: '28px', color: '#777', fontSize: '10px' }}>
          <h1>material-ui-color</h1>
          <h2>ColorPicker example</h2>
        </div>
        <ColorPicker value={color} palette={paletteObj} onChange={handleChange} />
        <Button variant="outlined" style={{ marginTop: '100px' }} onClick={() => handleChange('rgb(255, 0, 0)')}>
          set rgb(255, 0, 0)
        </Button>
        <div style={{ paddingTop: '180px', marginLeft: '-28px', color: '#999', fontSize: '12px' }}>
          https://github.com/mikbry/material-ui-color
        </div>
      </div>
      <div
        style={{
          color: '#777',
          marginLeft: '24px',
          width: '400px',
          height: '480px',
          backgroundColor: color.hex ? `#${color.hex}` : color,
        }}
      />
    </div>
  );
}
Example #11
Source File: create-component-story.js    From monday-ui-react-core with MIT License 6 votes vote down vote up
/**
 * Creates a decorator which maps a callback prop to an input prop.
 * For example: mapping the onChange callback of a Select component to its currentValue prop.
 * Useful for adding interactivity to stories of controlled components.
 * Additionally, the callback will trigger a Storybook action, that can be seen on the Actions tab.
 * @param {string} actionName - the name of the action prop of the component in the story. For example, "setValue" or "onChange".
 * @param {string} linkedToPropValue - the name of the prop which should be updated when the prop of "actionName" is called. For example, "value".
 * @returns A decorate for storybook which updates the {@link linkedToPropValue} input of the component, whenever {@link actionName} is called.
 */
function createMappedActionToInputPropDecorator(actionName, linkedToPropValue) {
  return (Story, context) => {
    const [propValue, setPropValue] = useState(context.initialArgs[linkedToPropValue]);
    const createAction = useMemo(() => action(actionName), []);

    const injectedCallback = useCallback(
      newPropValue => {
        setPropValue(newPropValue);
        createAction(newPropValue);
      },
      [setPropValue, createAction]
    );

    context.args[actionName] = injectedCallback;
    context.args[linkedToPropValue] = propValue;

    return Story();
  };
}
Example #12
Source File: button.stories.native.js    From polaris with Apache License 2.0 6 votes vote down vote up
storiesOf('Atoms/Button', module)
  .addDecorator(storyFn => (
    <StoryPage
      title="Native Button"
      url="components/atoms/button"
      storyFn={storyFn}
    >
      An example story in a <InlineCode code=".native.js" /> file. This story is
      only visible when exploring storybook on a native device
    </StoryPage>
  ))
  .addDecorator(withKnobs)
  .add('Native Only', () => (
    <DocItem
      sectionTitle="Native Only"
      name="title"
      description="The title to be used for the buttons content"
      typeInfo="string"
      required
      example={{
        render: (
          <Button
            onPress={action('Button Pressed')}
            title={text('text', 'Native Button')}
          />
        ),
        code: '<Button title="Native Button" onPress={handleButtonPress}>'
      }}
    />
  ))
Example #13
Source File: Checkbox.stories.js    From blade with MIT License 6 votes vote down vote up
storiesOf('Checkbox', module)
  .addParameters({
    component: Checkbox,
  })
  .add('defaultChecked', () => (
    <Flex flexDirection="column">
      <View>
        <Checkbox
          defaultChecked={boolean('Default Checked', false)}
          size={select('Size', sizeOptions, 'large')}
          title={text('Title', 'Enable Beast Mode')}
          helpText={text('Help Text', 'This is help text.')}
          disabled={boolean('Disabled', false)}
          onChange={action('Changed')}
        />
        <Checkbox
          defaultChecked={boolean('Default Checked', false)}
          size={select('Size', sizeOptions, 'large')}
          title={text('Title', 'Enable Beast Mode')}
          disabled={boolean('Disabled', false)}
          onChange={action('Changed')}
          errorText={text('Error Text', 'This is an error.')}
        />
      </View>
    </Flex>
  ))
  .add('checked', () => (
    <Checkbox
      checked={boolean('Checked', true)}
      size={select('Size', sizeOptions, 'large')}
      title={text('Title', 'Enable Beast Mode')}
      helpText={text('Help Text', 'Play with addons')}
      disabled={boolean('Disabled', false)}
      onChange={action('Changed')}
      errorText={text('Error Text', '')}
    />
  ));
Example #14
Source File: AlertModal.stories.js    From pollen with MIT License 5 votes vote down vote up
Default = () => ({
  components: { BaseButton, AlertModal },
  props: {
    cancelLabel: {
      default: text('Cancel label', 'Cancel'),
    },
    confirmLabel: {
      default: text('Confirm label', 'Continue'),
    },
    message: {
      default: text(
        'Message',
        'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
      ),
    },
    title: {
      default: text('Title', 'What a success!'),
    },
    variant: {
      default: select(
        'Variant',
        Object.values(Modal.Alerts),
        Modal.Alerts.SUCCESS
      ),
    },
  },
  data() {
    return { isModalOpen: true };
  },
  methods: {
    handleCancel: action('cancel'),
    handleConfirm: action('confirm'),
  },
  template: `
  <div>
    <BaseButton @click="isModalOpen = !isModalOpen">Toggle Modal</BaseButton>
    <AlertModal
      v-if="isModalOpen"
      :cancel-label="cancelLabel"
      :confirm-label="confirmLabel"
      :variant="variant"
      :title="title"
      :message="message"
      @close="isModalOpen = false"
      @cancel="handleCancel"
      @confirm="handleConfirm"
    />
  </div>
  `,
})
Example #15
Source File: Button.stories.js    From pollaris with MIT License 5 votes vote down vote up
handleClick = action('button clicked')
Example #16
Source File: Button.stories.js    From cypress-storybook with MIT License 5 votes vote down vote up
Emoji = () => (
  <Button onClick={action('clicked')}>
    <span role="img" aria-label="so cool">
      Emoji ? ? ? ?
    </span>
  </Button>
)
Example #17
Source File: 0-ReactTrixInputRTE.stories.js    From react-trix-rte with MIT License 5 votes vote down vote up
WithOnChangeHandler = () => (
  <ReactTrixRTEInput onChange={action('onChange')} />
)