From 6a4880ad142a268c2c8740a8e68330c7594537d1 Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Tue, 23 Feb 2021 09:50:52 +0100 Subject: [PATCH] Cascader: updates story from knobs to controls (#31399) --- .../components/Cascader/Cascader.story.tsx | 85 +++++++++++-------- .../src/components/Cascader/Cascader.tsx | 2 +- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx b/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx index c37b6ea72f2..f62024862f8 100644 --- a/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx +++ b/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx @@ -1,6 +1,8 @@ -import { text } from '@storybook/addon-knobs'; +import { Story } from '@storybook/react'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; +import { NOOP_CONTROL } from '../../../.storybook/preview'; import { Cascader } from '@grafana/ui'; +import { CascaderProps } from './Cascader'; import mdx from './Cascader.mdx'; import React from 'react'; @@ -12,50 +14,59 @@ export default { docs: { page: mdx, }, + knobs: { + disabled: true, + }, }, -}; - -const options = [ - { - label: 'First', - value: '1', - items: [ + args: { + onSelect: (val: string) => console.log(val), + options: [ { - label: 'Second', - value: '2', + label: 'First', + value: '1', + items: [ + { + label: 'Second', + value: '2', + }, + { + label: 'Third', + value: '3', + }, + { + label: 'Fourth', + value: '4', + }, + ], }, { - label: 'Third', - value: '3', - }, - { - label: 'Fourth', - value: '4', + label: 'FirstFirst', + value: '5', }, ], }, - { - label: 'FirstFirst', - value: '5', + argTypes: { + width: { control: { type: 'range', min: 0, max: 70 } }, + placeholder: NOOP_CONTROL, + initialValue: NOOP_CONTROL, + changeOnSelect: NOOP_CONTROL, }, -]; +}; -export const simple = () => ( - console.log(val)} /> -); -export const withInitialValue = () => ( - console.log(val)} /> -); +const Template: Story = (args) => ; -export const withCustomValue = () => { - const onCreateLabel = text('Custom value creation label', 'Create new value: '); - return ( - onCreateLabel + val} - initialValue="Custom Initial Value" - onSelect={(val) => console.log(val)} - /> - ); +export const Simple = Template.bind({}); +Simple.args = { + separator: '', +}; +export const WithInitialValue = Template.bind({}); +WithInitialValue.args = { + initialValue: '3', +}; + +export const WithCustomValue = Template.bind({}); +WithCustomValue.args = { + initialValue: 'Custom Initial Value', + allowCustomValue: true, + formatCreateLabel: (val) => 'Custom Label' + val, }; diff --git a/packages/grafana-ui/src/components/Cascader/Cascader.tsx b/packages/grafana-ui/src/components/Cascader/Cascader.tsx index 15eefa07151..99d32b49329 100644 --- a/packages/grafana-ui/src/components/Cascader/Cascader.tsx +++ b/packages/grafana-ui/src/components/Cascader/Cascader.tsx @@ -8,7 +8,7 @@ import { SelectableValue } from '@grafana/data'; import { css } from 'emotion'; import { onChangeCascader } from './optionMappings'; -interface CascaderProps { +export interface CascaderProps { /** The separator between levels in the search */ separator?: string; placeholder?: string;