Package Tansy UI as @openkhalix/tansy-ui in a monorepo (v0.4.0)
Restructure the repo into npm workspaces so the component kit publishes as its own package, like MUI and shadcn/ui: - packages/ui: @openkhalix/tansy-ui (published), with components, stories, tests, tokens and the library build - packages/brand: private logo and catalogue data shared by both apps - apps/site: the landing page - apps/docs: Storybook The package: - MIT licence (copyright OpenKhalix) - per-component ES modules and type declarations - "use client" on component modules so they import into Next.js Server Components; helpers stay server-safe - tokens.css for Tailwind v4 apps, and a prebuilt styles.css for apps without Tailwind - lucide-react 1.x, whose types compile against current React 19 types The apps resolve the package through a "source" export condition, so they hot-reload component edits, while outside users get dist/. scripts/test-package.mjs packs the package and installs the tarball into Vite + Tailwind (strict types), plain React and Next.js apps; each must build and render correctly. Gitea workflows run CI on push and publish to npm when a vX.Y.Z tag matching the package version is pushed.
This commit is contained in:
1 parent
23e67006d3
commit
9255b255a6
214 files changed
+1521
-389
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { useEffect, type ReactNode } from 'react'
|
||||
import { applyPalette, type PaletteName } from '@openkhalix/tansy-ui'
|
||||
|
||||
/**
|
||||
* Applies the toolbar's palette and light/dark mode to <html>.
|
||||
*
|
||||
* It has to be the root element, not a wrapper: Base UI renders popups (menus,
|
||||
* selects, dialogs, toasts) into a portal on document.body, and they must pick
|
||||
* up the same tokens as the story.
|
||||
*/
|
||||
export function ThemeSurface({
|
||||
palette,
|
||||
mode,
|
||||
padded,
|
||||
children,
|
||||
}: {
|
||||
palette: PaletteName
|
||||
mode: 'light' | 'dark'
|
||||
padded: boolean
|
||||
children: ReactNode
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const root = document.documentElement
|
||||
applyPalette(root, palette)
|
||||
root.classList.toggle('dark', mode === 'dark')
|
||||
root.dataset.palette = palette
|
||||
document.body.style.background = 'var(--color-background)'
|
||||
document.body.style.color = 'var(--color-fg)'
|
||||
}, [palette, mode])
|
||||
|
||||
return <div style={{ padding: padded ? '1.5rem' : 0, minHeight: '100%' }}>{children}</div>
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { StorybookConfig } from '@storybook/react-vite'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
|
||||
const config: StorybookConfig = {
|
||||
stories: ['../src/**/*.mdx', '../../../packages/ui/src/**/*.stories.@(ts|tsx)'],
|
||||
addons: [
|
||||
{
|
||||
name: '@storybook/addon-docs',
|
||||
// GitHub-flavoured Markdown, so tables in the Introduction pages render.
|
||||
options: { mdxPluginOptions: { mdxCompileOptions: { remarkPlugins: [remarkGfm] } } },
|
||||
},
|
||||
'@storybook/addon-a11y',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
// Serves the Tansy mark and favicon to the manager and the Welcome page.
|
||||
staticDirs: ['../../../packages/brand/public'],
|
||||
docs: {
|
||||
defaultName: 'Documentation',
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -0,0 +1,8 @@
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Schibsted+Grotesk:wght@700;800&display=swap"
|
||||
/>
|
||||
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
|
||||
<meta name="theme-color" content="#f3f4f6" />
|
||||
@@ -0,0 +1,9 @@
|
||||
import { addons } from 'storybook/manager-api'
|
||||
import { tansyTheme } from './tansyTheme'
|
||||
|
||||
addons.setConfig({
|
||||
theme: tansyTheme,
|
||||
sidebar: {
|
||||
showRoots: true,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,11 @@
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Schibsted+Grotesk:wght@700;800&display=swap"
|
||||
/>
|
||||
<style>
|
||||
/* Tailwind's preflight strips list markers; restore them on docs pages. */
|
||||
.sbdocs ol { list-style: decimal; padding-left: 1.5rem; }
|
||||
.sbdocs h2 { font-family: "Schibsted Grotesk", sans-serif; font-weight: 800; letter-spacing: -0.02em; }
|
||||
</style>
|
||||
@@ -0,0 +1,90 @@
|
||||
import type { Decorator, Preview } from '@storybook/react-vite'
|
||||
import '../src/styles.css'
|
||||
import { palettes, DEFAULT_PALETTE, type PaletteName } from '@openkhalix/tansy-ui'
|
||||
import { tansyTheme } from './tansyTheme'
|
||||
import { ThemeSurface } from './ThemeSurface'
|
||||
|
||||
const withTheme: Decorator = (Story, context) => {
|
||||
const palette = (context.globals.palette ?? DEFAULT_PALETTE) as PaletteName
|
||||
const mode = context.globals.mode === 'dark' ? 'dark' : 'light'
|
||||
const padded = context.parameters.layout !== 'fullscreen'
|
||||
return (
|
||||
<ThemeSurface palette={palette} mode={mode} padded={padded}>
|
||||
<Story />
|
||||
</ThemeSurface>
|
||||
)
|
||||
}
|
||||
|
||||
const preview: Preview = {
|
||||
title: 'Tansy UI / Component Workshop',
|
||||
decorators: [withTheme],
|
||||
globalTypes: {
|
||||
mode: {
|
||||
description: 'Light or dark mode for every component and popup.',
|
||||
toolbar: {
|
||||
title: 'Mode',
|
||||
icon: 'contrast',
|
||||
items: [
|
||||
{ value: 'light', title: 'Light', icon: 'sun' },
|
||||
{ value: 'dark', title: 'Dark', icon: 'moon' },
|
||||
],
|
||||
dynamicTitle: true,
|
||||
},
|
||||
},
|
||||
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: {
|
||||
mode: 'light',
|
||||
palette: DEFAULT_PALETTE,
|
||||
},
|
||||
parameters: {
|
||||
backgrounds: { disable: true },
|
||||
a11y: {
|
||||
// Page-level rules can't apply to an isolated component: a story has no
|
||||
// <main>, no <h1> and no landmarks of its own. Everything else runs.
|
||||
config: {
|
||||
rules: [
|
||||
{ id: 'landmark-one-main', enabled: false },
|
||||
{ id: 'page-has-heading-one', enabled: false },
|
||||
{ id: 'region', enabled: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
docs: {
|
||||
theme: tansyTheme,
|
||||
},
|
||||
options: {
|
||||
storySort: {
|
||||
order: [
|
||||
'Introduction',
|
||||
['Welcome', 'Getting started', 'Theming', 'Accessibility', 'Changelog', 'Roadmap'],
|
||||
'Actions',
|
||||
'Forms',
|
||||
'Feedback',
|
||||
'Display',
|
||||
'Layout',
|
||||
'Navigation',
|
||||
'Overlays',
|
||||
],
|
||||
},
|
||||
},
|
||||
controls: {
|
||||
matchers: {
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default preview
|
||||
@@ -0,0 +1,46 @@
|
||||
import { create } from 'storybook/theming'
|
||||
|
||||
/**
|
||||
* Tansy UI branding for the Storybook manager and docs pages.
|
||||
*
|
||||
* `brandTitle` is HTML: the mark comes from `public/` (served via `staticDirs`)
|
||||
* and is referenced relatively so it resolves both at `/` in dev and under
|
||||
* `/docs/` in production.
|
||||
*/
|
||||
export const tansyTheme = create({
|
||||
base: 'light',
|
||||
|
||||
brandTitle: `<span style="display:inline-flex;align-items:center;gap:8px;white-space:nowrap">
|
||||
<img src="./tansy-mark.svg" width="28" height="28" alt="" />
|
||||
<span style="font-family:'Schibsted Grotesk',sans-serif;font-weight:800;font-size:19px;letter-spacing:-0.03em;color:#12151c">Tansy <span style="font-weight:700;color:#6b7384">UI</span></span>
|
||||
<span style="font-size:11px;color:#6b7384;padding-left:8px;border-left:1px solid #c5cad4">by OpenKhalix</span>
|
||||
</span>`,
|
||||
brandUrl: '/',
|
||||
brandTarget: '_self',
|
||||
|
||||
colorPrimary: '#305ddd',
|
||||
colorSecondary: '#305ddd',
|
||||
|
||||
appBg: '#f3f4f6',
|
||||
appContentBg: '#ffffff',
|
||||
appPreviewBg: '#ffffff',
|
||||
appBorderColor: '#dde1e8',
|
||||
appBorderRadius: 8,
|
||||
|
||||
fontBase: '"Instrument Sans", "Helvetica Neue", Arial, sans-serif',
|
||||
fontCode: '"JetBrains Mono", "SFMono-Regular", Consolas, monospace',
|
||||
|
||||
textColor: '#12151c',
|
||||
textInverseColor: '#ffffff',
|
||||
textMutedColor: '#6b7384',
|
||||
|
||||
barBg: '#ffffff',
|
||||
barTextColor: '#4a5162',
|
||||
barSelectedColor: '#305ddd',
|
||||
barHoverColor: '#305ddd',
|
||||
|
||||
inputBg: '#ffffff',
|
||||
inputBorder: '#c5cad4',
|
||||
inputTextColor: '#12151c',
|
||||
inputBorderRadius: 6,
|
||||
})
|
||||
Reference in new issue
Block a user