Skip to content

Commit

Permalink
Add theme selector to Storybook
Browse files Browse the repository at this point in the history
Update Storybook to allow testing of both light and dark modes
for all component previews.

Some components such as the Log / YAML display are designed for
dark mode only so these specify an override.
  • Loading branch information
AlanGreene authored and tekton-robot committed Sep 4, 2023
1 parent 8a4b3ad commit 24dda99
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 96 deletions.
9 changes: 9 additions & 0 deletions .storybook/Container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ limitations under the License.
@import '@tektoncd/dashboard-graph/src/components/ZoomablePipelineGraph.scss';

@import '@tektoncd/dashboard-graph/src/components/newGraph.scss';

.tkn--storybook-theme {
background-color: $ui-background;
color: $text-01;

.sb-show-main {
background-color: inherit !important;
}
}
5 changes: 0 additions & 5 deletions .storybook/Welcome.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import tektonDashboardLogo from '../src/images/tekton-dashboard-color.svg';

<Meta
name="Welcome"
parameters={{
backgrounds: {
default: 'gray10'
}
}}
title="Getting started/Welcome"
/>

Expand Down
3 changes: 2 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const config = {
addons: [
'@storybook/addon-essentials',
'@storybook/addon-links',
'@storybook/addon-storysource'
'@storybook/addon-storysource',
'@storybook/addon-themes'
],
core: { disableTelemetry: true },
docs: {
Expand Down
19 changes: 11 additions & 8 deletions .storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ limitations under the License.
*/

import React from 'react';
import { withThemeByClassName } from '@storybook/addon-themes';

import Container from './Container';

Expand All @@ -22,26 +23,28 @@ const parameters = {
}
},
backgrounds: {
default: 'gray10',
disable: true,
grid: {
disable: true,
cellSize: 16,
opacity: 0.2,
cellAmount: 1,
offsetX: 0,
offsetY: 0
},
values: [
{ name: 'white', value: 'white' },
{ name: 'gray10', value: '#f4f4f4' },
{ name: 'gray90', value: '#262626' },
{ name: 'debug', value: 'red' }
]
}
},
controls: { hideNoControlsWarning: true }
};

const decorators = [
withThemeByClassName({
themes: {
light: 'tkn--theme-light tkn--storybook-theme',
dark: 'tkn--theme-dark tkn--storybook-theme',
system: 'tkn--theme-system tkn--storybook-theme'
},
defaultTheme: 'system'
}),
(story, context) => (
<Container
notes={context.parameters.notes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import DeleteModal from './DeleteModal';

export default {
component: DeleteModal,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'DeleteModal'
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2022 The Tekton Authors
Copyright 2019-2023 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -12,6 +12,7 @@ limitations under the License.
*/

header.tkn--step-details-header {
background-color: $ui-01;
padding: 1rem 1rem 0;

h2.tkn--details-header--heading {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export default {
}
},
component: DetailsHeader,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'DetailsHeader'
};

Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/components/Log/Log.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export default {
</div>
)
],
parameters: {
themes: {
themeOverride: 'dark'
}
},
title: 'Log'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ const ansiTextStyles = (() => {

export default {
component: LogFormat,
parameters: {
themes: {
themeOverride: 'dark'
}
},
title: 'LogFormat'
};

export const Colors = {
args: {
children: ansiColors
},
parameters: {
backgrounds: {
default: 'gray90'
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export default {
options: ['normal', 'inverse']
}
},
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'StatusIcon'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/components/src/components/Step/Step.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export default {
stepName: 'build'
},
component: Step,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'Step'
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2021 The Tekton Authors
Copyright 2019-2023 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -12,6 +12,7 @@ limitations under the License.
*/

.tkn--step-details {
background-color: $ui-01;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export default {
taskRun: {}
},
component: StepDetails,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'StepDetails'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/components/src/components/Tabs/Tabs.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import Tab from '../Tab';

export default {
component: Tabs,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'Tabs'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const results = [{ name: 'message', value: 'hello' }];

export default {
component: TaskRunDetails,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'TaskRunDetails'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ const props = {

export default {
component: Trigger,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'Trigger'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default {
}
},
component: ViewYAML,
parameters: {
themes: {
themeOverride: 'dark'
}
},
title: 'ViewYAML'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/graph/src/components/Graph.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import graph from './examples/graph.json';

export default {
component: Graph,
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'legacy/Graph'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/graph/src/components/Graph/Graph.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export default {
options: ['DOWN', 'RIGHT']
}
},
parameters: {
backgrounds: {
default: 'gray10'
}
},
title: 'Graph'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/graph/src/components/Node.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ export default {
</div>
)
],
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'legacy/Node'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/graph/src/components/Node/Node.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ export default {
options: ['card', 'icon']
}
},
parameters: {
backgrounds: {
default: 'gray10'
}
},
title: 'Node'
};

Expand Down
5 changes: 0 additions & 5 deletions packages/graph/src/components/PipelineGraph.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import taskRuns from './examples/taskRuns.json';
import tasks from './examples/tasks.json';

export default {
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'legacy/PipelineGraph'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export default {
]
}
},
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'StatusIcon'
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import taskRuns from './examples/taskRuns.json';
import tasks from './examples/tasks.json';

export default {
parameters: {
backgrounds: {
default: 'white'
}
},
title: 'legacy/ZoomablePipelineGraph'
};

Expand Down

0 comments on commit 24dda99

Please sign in to comment.