mirror of
https://github.com/hanzoai/cd-ui.git
synced 2026-10-30 20:42:45 +00:00
* chore(storybook): update v1 syntax to use Storybook v6
- while the deps used Storybook v6, the configuration and stories themselves were still on a legacy v5 format
- v6 had backward compat for v5, but v7 does not, so this needs upgrading/migrating
- or well, v7 has some legacy mode for it that can be enabled with some config, but it is entirely gone in v8
- migrate `storiesOf` to CSF per https://storybook.js.org/docs/7/migration-guide#storiesof-to-csf
- then had to do a bunch of manual changes to get back mostly the same previous indentation (with some minor differences where there were mistakes or inconsistencies)
- tried to keep the diff as small as possible
- CSF is still valid through to latest v8
Signed-off-by: Anton Gilgur <[email protected]>
* chore(storybook): convert v1 config to use Storybook v6
- modified version of v2's config
Signed-off-by: Anton Gilgur <[email protected]>
* fixup config a bit -- take more from prev webpack config
- `ts-loader` is necessary to handle the `import type` syntax
- custom `tsconfig.json` doesn't seem necessary though
- use same SASS config
- plain CSS config not needed though bc PostCSS already runs by default
Signed-off-by: Anton Gilgur <[email protected]>
* rename to `.stories.tsx` and remove `index`
- the conventional format
- also had some problems finding stories without this change
Signed-off-by: Anton Gilgur <[email protected]>
* fix deprecation warning re: `storyName`
- per https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#hoisted-csf-annotations
- migrate `.story.name` -> `.storyName`
- not sure why the automigration didn't do this and instead used the deprecated name 😕
Signed-off-by: Anton Gilgur <[email protected]>
* also fix history deprecation warning
Signed-off-by: Anton Gilgur <[email protected]>
* attempt to load CSS properly but still fail
Signed-off-by: Anton Gilgur <[email protected]>
* improve perf with built in loader for TS
- remove `ts-loader` as not necessary
- plus some settings for Storybook's TS loader preset
Signed-off-by: Anton Gilgur <[email protected]>
* diff reduction
Signed-off-by: Anton Gilgur <[email protected]>
* more diff reduction
Signed-off-by: Anton Gilgur <[email protected]>
* more diff reduction
Signed-off-by: Anton Gilgur <[email protected]>
* attempt to reduce diff a bit more hackily
Signed-off-by: Anton Gilgur <[email protected]>
* one more diff reduction with one hackishness
Signed-off-by: Anton Gilgur <[email protected]>
* diff reduction with older wacky syntax
Signed-off-by: Anton Gilgur <[email protected]>
* slightly better syntax than previous while retaining indentation
Signed-off-by: Anton Gilgur <[email protected]>
* last diff reduction/indentation change
Signed-off-by: Anton Gilgur <[email protected]>
* missing trailing comma
Signed-off-by: Anton Gilgur <[email protected]>
---------
Signed-off-by: Anton Gilgur <[email protected]>
187 lines
6.2 KiB
TypeScript
187 lines
6.2 KiB
TypeScript
import { createBrowserHistory } from 'history';
|
|
import * as React from 'react';
|
|
import { Route, Router } from 'react-router';
|
|
import { timer } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { Layout } from '../src/components/layout/layout';
|
|
import { Page } from '../src/components/page/page';
|
|
|
|
const navItems = [{ path: location.pathname, title: 'Sample', iconClassName: 'argo-icon-docs' }];
|
|
const breadcrumbs = [{
|
|
title: 'breadcrumb parent',
|
|
path: location.pathname,
|
|
}, {
|
|
title: 'this page breadcrumb',
|
|
}];
|
|
|
|
const actionMenu = {
|
|
items: [{
|
|
title: 'New Item 1',
|
|
iconClassName: 'fa fa-history',
|
|
action: () => {
|
|
// do nothing
|
|
},
|
|
}, {
|
|
title: 'New Item 2',
|
|
iconClassName: 'icon argo-icon-deploy',
|
|
action: () => {
|
|
// do nothing
|
|
},
|
|
},
|
|
{
|
|
title: 'New Item 3',
|
|
action: () => {
|
|
// do nothing
|
|
},
|
|
},
|
|
{
|
|
title: 'New Item 4',
|
|
iconClassName: 'fa fa-times-circle',
|
|
disabled: true,
|
|
action: () => {
|
|
// do nothing
|
|
},
|
|
}],
|
|
};
|
|
|
|
const history = createBrowserHistory();
|
|
|
|
function ensureSelected(vals: string[], selected: string[]): string[] {
|
|
const res = new Set(selected);
|
|
vals.forEach((item) => res.add(item));
|
|
return Array.from(res);
|
|
}
|
|
|
|
export default {
|
|
title: 'Page',
|
|
};
|
|
|
|
export const Default = () => {
|
|
const [selectedFilter, setSelectedFilter] = React.useState<string[]>([]);
|
|
return (
|
|
<Router history={history}>
|
|
<Route path={location.pathname}>
|
|
<Layout navItems={navItems}>
|
|
<Page title='Hello world!' toolbar={{breadcrumbs, actionMenu, filter: {
|
|
items: [
|
|
{
|
|
content: (changeSelection) => (
|
|
<React.Fragment>
|
|
Filter type one: <a onClick={() => changeSelection(ensureSelected(['1', '2'], selectedFilter))}>all</a>
|
|
</React.Fragment>
|
|
),
|
|
},
|
|
{ label: 'filter 1', value: '1' },
|
|
{ label: 'filter 2', value: '2' },
|
|
{
|
|
content: (changeSelection) => (
|
|
<React.Fragment>
|
|
Filter type two: <a onClick={() => changeSelection(ensureSelected(['3', '4'], selectedFilter))}>all</a>
|
|
</React.Fragment>
|
|
),
|
|
},
|
|
{ label: 'filter 3', value: '3' },
|
|
{ label: 'filter 4', value: '4' },
|
|
],
|
|
selectedValues: selectedFilter,
|
|
selectionChanged: setSelectedFilter,
|
|
}}}>
|
|
<div style={{ padding: '1em' }}>
|
|
<div className='white-box'>
|
|
Hello world!
|
|
</div>
|
|
</div>
|
|
</Page>
|
|
</Layout>
|
|
</Route>
|
|
</Router>
|
|
)
|
|
};
|
|
Default.storyName = 'default';
|
|
|
|
export const DynamicToolbar = () => {
|
|
return (
|
|
<Router history={history}>
|
|
<Route path={location.pathname}>
|
|
<Layout navItems={navItems}>
|
|
<Page title='Hello world!' toolbar={timer(0, 1000).pipe(map(() => ({breadcrumbs: [
|
|
{ title: 'hello ' + new Date().toLocaleTimeString() },
|
|
]})))}>
|
|
<div style={{ padding: '1em' }}>
|
|
<div className='white-box'>Hello world!</div>
|
|
</div>
|
|
</Page>
|
|
</Layout>
|
|
</Route>
|
|
</Router>
|
|
);
|
|
}
|
|
DynamicToolbar.storyName = 'dynamic toolbar';
|
|
|
|
export const CompactNavBar = () => {
|
|
const manyNavItems = [];
|
|
for (let i = 0; i < 10; i++) {
|
|
manyNavItems.push({path: location.pathname + '/' + i, title: 'Sample', iconClassName: 'argo-icon-docs'});
|
|
}
|
|
return (
|
|
(
|
|
<Router history={history}>
|
|
<Route path={location.pathname}>
|
|
<Layout navItems={manyNavItems}>
|
|
<Page title='Hello world!'>
|
|
<div style={{ padding: '1em' }}>
|
|
<div className='white-box'>
|
|
Hello world!
|
|
</div>
|
|
</div>
|
|
</Page>
|
|
</Layout>
|
|
</Route>
|
|
</Router>
|
|
)
|
|
);
|
|
};
|
|
CompactNavBar.storyName = 'compact nav bar';
|
|
|
|
export const CustomTopBarTitle = () => {
|
|
return (
|
|
<Router history={history}>
|
|
<Route path={location.pathname}>
|
|
<Layout navItems={navItems}>
|
|
<Page title='helmet title' topBarTitle='Top Bar Title' toolbar={{breadcrumbs: [
|
|
{ title: 'Apps ', path: '/applications' },
|
|
{ title: 'app name' },
|
|
]}}>
|
|
<div style={{ padding: '1em' }}>
|
|
<div className='white-box'>
|
|
Test
|
|
</div>
|
|
</div>
|
|
</Page>
|
|
</Layout>
|
|
</Route>
|
|
</Router>
|
|
);
|
|
}
|
|
CustomTopBarTitle.storyName = 'custom top bar title';
|
|
|
|
export const BackgroundColor = () => {
|
|
return (
|
|
<Router history={history}>
|
|
<Route path={location.pathname}>
|
|
<Layout navItems={navItems} navBarStyle={{ backgroundColor: 'red' }}>
|
|
<Page title='Hello world!'>
|
|
<div style={{ padding: '1em' }}>
|
|
<div className='white-box'>
|
|
Hello world!
|
|
</div>
|
|
</div>
|
|
</Page>
|
|
</Layout>
|
|
</Route>
|
|
</Router>
|
|
);
|
|
}
|
|
BackgroundColor.storyName = 'background color';
|