Tansy UI: a themeable React component kit
Tansy UI is a React component kit by OpenKhalix, named after the tansy
flower ("golden buttons"). It has two surfaces:
- A landing page built entirely from the kit's own components, with
five featured parts, a palette-switching playground form, and links
into Storybook
- A Storybook workshop with Tansy branding, a Welcome page, palette
toolbar and accessibility checks
Includes 15 components with colocated tokens and stories, seven brand
palettes, a palette-aware logo, a Docker/nginx image, a scripted
cPanel deploy, and a generator that keeps the landing page catalogue
in sync with Storybook.
This commit is contained in:
commit
9d406d6d2a
81 files changed
+14240
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { useEffect, useRef, type ReactElement } from 'react'
|
||||
import type { Decorator, Preview } from '@storybook/react-vite'
|
||||
import '../src/index.css'
|
||||
import { applyPalette } from '../src/theme/applyPalette'
|
||||
import { palettes, DEFAULT_PALETTE, type PaletteName } from '../src/theme/palettes'
|
||||
import { tansyTheme } from './tansyTheme'
|
||||
|
||||
/**
|
||||
* Wraps every story in a themed surface.
|
||||
*
|
||||
* The palette globals are set on this wrapper rather than on
|
||||
* `document.documentElement` so a story can opt into a *different* palette on
|
||||
* its own subtree without fighting the global one, and so the docs page keeps
|
||||
* its own chrome.
|
||||
*
|
||||
* Declared as a named component (not an inline arrow) so the rules-of-hooks lint
|
||||
* recognises the hook calls below.
|
||||
*/
|
||||
function PaletteSurface({ palette, children }: { palette: PaletteName; children: ReactElement }) {
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) applyPalette(ref.current, palette)
|
||||
}, [palette])
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-palette={palette}
|
||||
style={{
|
||||
padding: '1.5rem',
|
||||
minHeight: '100%',
|
||||
color: 'var(--color-gray-900)',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const withPalette: Decorator = (Story, context) => {
|
||||
const palette = (context.globals.palette ?? DEFAULT_PALETTE) as PaletteName
|
||||
return <PaletteSurface palette={palette}><Story /></PaletteSurface>
|
||||
}
|
||||
|
||||
const preview: Preview = {
|
||||
title: 'Tansy UI / Component Workshop',
|
||||
decorators: [withPalette],
|
||||
globalTypes: {
|
||||
palette: {
|
||||
description: 'Brand palette applied to every element in the canvas.',
|
||||
toolbar: {
|
||||
title: 'Palette',
|
||||
icon: 'paintbrush',
|
||||
items: Object.values(palettes).map((p) => ({
|
||||
value: p.name,
|
||||
title: `${p.label} — ${p.note}`,
|
||||
})),
|
||||
dynamicTitle: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
initialGlobals: {
|
||||
palette: DEFAULT_PALETTE,
|
||||
},
|
||||
parameters: {
|
||||
docs: {
|
||||
theme: tansyTheme,
|
||||
},
|
||||
options: {
|
||||
storySort: {
|
||||
order: ['Welcome', 'Actions', 'Forms', 'Data entry', 'Feedback', 'Display', 'Layout', 'Navigation', 'Overlays'],
|
||||
},
|
||||
},
|
||||
backgrounds: {
|
||||
default: 'showcase',
|
||||
values: [
|
||||
{ name: 'showcase', value: '#f3f4f6' },
|
||||
{ name: 'surface', value: '#ffffff' },
|
||||
{ name: 'dark', value: '#12151c' },
|
||||
],
|
||||
},
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default preview
|
||||
Reference in new issue
Block a user