-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add react-widget to storybook (#120)
- Loading branch information
Showing
21 changed files
with
478 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
packages/react-ui/storybook/stories/widgets/CategoryWidget.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { | ||
Title, | ||
Subtitle, | ||
Primary, | ||
ArgsTable, | ||
Stories, | ||
PRIMARY_STORY | ||
} from '@storybook/addon-docs/blocks'; | ||
import * as cartoSlice from '../../../../react-redux/src/slices/cartoSlice'; | ||
import { AggregationTypes } from '../../../../react-core/src'; | ||
import CategoryWidget from '../../../../react-widgets/src/widgets/CategoryWidget'; | ||
import { mockAppStoreConfiguration } from './utils'; | ||
|
||
const store = mockAppStoreConfiguration(); | ||
store.dispatch( | ||
cartoSlice.setWidgetLoadingState({ widgetId: 'sb-category-id', isLoading: false }) | ||
); | ||
|
||
const mockedData = [...Array(30)].map((_, idx) => ({ | ||
'sb-column': `Category ${ | ||
idx < 5 ? '1' : idx < 10 ? '2' : idx < 15 ? '3' : idx < 20 ? '4' : '5' | ||
}`, | ||
'sb-operation-column': idx * 100 | ||
})); | ||
store.dispatch( | ||
cartoSlice.setViewportFeatures({ sourceId: 'sb-data-source', features: mockedData }) | ||
); | ||
|
||
const options = { | ||
title: 'Widgets/CategoryWidget', | ||
component: CategoryWidget, | ||
decorators: [ | ||
(Story) => ( | ||
<Provider store={store}> | ||
<Story /> | ||
</Provider> | ||
) | ||
], | ||
argTypes: { | ||
operation: { | ||
control: { | ||
type: 'select', | ||
options: Object.values(AggregationTypes) | ||
} | ||
} | ||
}, | ||
parameters: { | ||
docs: { | ||
page: () => ( | ||
<> | ||
<Title /> | ||
<Subtitle /> | ||
<Primary /> | ||
<ArgsTable story={PRIMARY_STORY} /> | ||
<Stories /> | ||
</> | ||
) | ||
} | ||
} | ||
}; | ||
|
||
export default options; | ||
|
||
const Template = (args) => <CategoryWidget {...args} />; | ||
|
||
const DEFAULT_PROPS = { | ||
id: 'sb-category-id', | ||
title: 'wrapper title', | ||
dataSource: 'sb-data-source', | ||
column: 'sb-column', | ||
operationColumn: 'sb-operation-column', | ||
operation: 'sum' | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = DEFAULT_PROPS; | ||
|
||
export const WithFormatter = Template.bind({}); | ||
WithFormatter.args = { ...DEFAULT_PROPS, formatter: (v) => `$${v}` }; | ||
|
||
export const WithCustomLabels = Template.bind({}); | ||
WithCustomLabels.args = { | ||
...DEFAULT_PROPS, | ||
labels: { | ||
'Category 1': 'Cat. 1', | ||
'Category 2': 'Cat. 2', | ||
'Category 3': 'Cat. 3', | ||
'Category 4': 'Cat. 4', | ||
'Category 5': 'Cat. 5' | ||
} | ||
}; |
76 changes: 76 additions & 0 deletions
76
packages/react-ui/storybook/stories/widgets/FormulaWidget.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { | ||
Title, | ||
Subtitle, | ||
Primary, | ||
ArgsTable, | ||
Stories, | ||
PRIMARY_STORY | ||
} from '@storybook/addon-docs/blocks'; | ||
import * as cartoSlice from '../../../../react-redux/src/slices/cartoSlice'; | ||
import { AggregationTypes } from '../../../../react-core/src'; | ||
import FormulaWidget from '../../../../react-widgets/src/widgets/FormulaWidget'; | ||
import { mockAppStoreConfiguration } from './utils'; | ||
|
||
const store = mockAppStoreConfiguration(); | ||
store.dispatch( | ||
cartoSlice.setWidgetLoadingState({ widgetId: 'sb-formula-id', isLoading: false }) | ||
); | ||
store.dispatch( | ||
cartoSlice.setViewportFeatures({ | ||
sourceId: 'sb-data-source', | ||
features: [{ 'sb-column': 5000 }, { 'sb-column': 5000 }] | ||
}) | ||
); | ||
|
||
const options = { | ||
title: 'Widgets/FormulaWidget', | ||
component: FormulaWidget, | ||
decorators: [ | ||
(Story) => ( | ||
<Provider store={store}> | ||
<Story /> | ||
</Provider> | ||
) | ||
], | ||
argTypes: { | ||
operation: { | ||
control: { | ||
type: 'select', | ||
options: Object.values(AggregationTypes) | ||
} | ||
} | ||
}, | ||
parameters: { | ||
docs: { | ||
page: () => ( | ||
<> | ||
<Title /> | ||
<Subtitle /> | ||
<Primary /> | ||
<ArgsTable story={PRIMARY_STORY} /> | ||
<Stories /> | ||
</> | ||
) | ||
} | ||
} | ||
}; | ||
|
||
export default options; | ||
|
||
const Template = (args) => <FormulaWidget {...args} />; | ||
|
||
const DEFAULT_PROPS = { | ||
id: 'sb-formula-id', | ||
title: 'wrapper title', | ||
dataSource: 'sb-data-source', | ||
column: 'sb-column', | ||
operation: 'sum' | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = DEFAULT_PROPS; | ||
|
||
export const WithFormatter = Template.bind({}); | ||
WithFormatter.args = { ...DEFAULT_PROPS, formatter: (v) => `$${v}` }; |
81 changes: 81 additions & 0 deletions
81
packages/react-ui/storybook/stories/widgets/HistogramWidget.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { | ||
Title, | ||
Subtitle, | ||
Primary, | ||
ArgsTable, | ||
Stories, | ||
PRIMARY_STORY | ||
} from '@storybook/addon-docs/blocks'; | ||
import * as cartoSlice from '../../../../react-redux/src/slices/cartoSlice'; | ||
import { AggregationTypes } from '../../../../react-core/src'; | ||
import HistogramWidget from '../../../../react-widgets/src/widgets/HistogramWidget'; | ||
import { mockAppStoreConfiguration } from './utils'; | ||
|
||
const store = mockAppStoreConfiguration(); | ||
store.dispatch( | ||
cartoSlice.setWidgetLoadingState({ widgetId: 'sb-histogram-id', isLoading: false }) | ||
); | ||
|
||
const mockedData = [...Array(40)].map((_, idx) => ({ | ||
'sb-column': idx < 10 ? 100 : idx < 25 ? 200 : idx < 33 ? 300 : idx < 35 ? 400 : 500 | ||
})); | ||
store.dispatch( | ||
cartoSlice.setViewportFeatures({ sourceId: 'sb-data-source', features: mockedData }) | ||
); | ||
|
||
const options = { | ||
title: 'Widgets/HistogramWidget', | ||
component: HistogramWidget, | ||
decorators: [ | ||
(Story) => ( | ||
<Provider store={store}> | ||
<Story /> | ||
</Provider> | ||
) | ||
], | ||
argTypes: { | ||
operation: { | ||
control: { | ||
type: 'select', | ||
options: Object.values(AggregationTypes) | ||
} | ||
} | ||
}, | ||
parameters: { | ||
docs: { | ||
page: () => ( | ||
<> | ||
<Title /> | ||
<Subtitle /> | ||
<Primary /> | ||
<ArgsTable story={PRIMARY_STORY} /> | ||
<Stories /> | ||
</> | ||
) | ||
} | ||
} | ||
}; | ||
|
||
export default options; | ||
|
||
const Template = (args) => <HistogramWidget {...args} />; | ||
|
||
const DEFAULT_PROPS = { | ||
id: 'sb-histogram-id', | ||
title: 'wrapper title', | ||
dataSource: 'sb-data-source', | ||
column: 'sb-column', | ||
ticks: [200, 300, 400, 500], | ||
operation: 'count' | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = DEFAULT_PROPS; | ||
|
||
export const xAxisFormatter = Template.bind({}); | ||
xAxisFormatter.args = { ...DEFAULT_PROPS, xAxisFormatter: (v) => `${v}$` }; | ||
|
||
export const yAxisFormatter = Template.bind({}); | ||
yAxisFormatter.args = { ...DEFAULT_PROPS, formatter: (v) => `$${v}` }; |
Oops, something went wrong.