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:
thekhalidsha committed 2026-09-28 17:09:57 +05:30
commit 9d406d6d2a
81 files changed
+14240

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
/**
* Merge Tailwind class names safely.
*
* Ported verbatim in behaviour from the source app's
* `src/common/utils/classNames.js`, which every component imports. `clsx`
* handles conditional/array/object inputs; `twMerge` resolves conflicts so the
* last utility wins (e.g. `cn('px-2', 'px-4')` yields `px-4`).
*/
export function cn(...inputs: ClassValue[]): string {
return twMerge(clsx(inputs))
}
+16
View File
@@ -0,0 +1,16 @@
/**
* Omit specific keys from an object.
*
* Ported from the source app's `src/common/utils/omit.js`, used by form
* components to strip internal-only props (form-library plumbing) before
* spreading the rest onto the DOM node.
*/
export function omit<T extends object, K extends keyof T>(
obj: T | null | undefined,
keys: readonly (K | string)[],
): Omit<T, K> {
if (!obj) return {} as Omit<T, K>
return Object.fromEntries(
Object.entries(obj).filter(([k]) => !keys.includes(k)),
) as Omit<T, K>
}
+29
View File
@@ -0,0 +1,29 @@
import { useEffect, type RefObject } from 'react'
/**
* Fire `callback` when a mousedown lands outside every one of `elements`.
*
* Ported from the source app's `Select/hooks/useClickOutside`.
* The dropdown is portalled to `document.body`, so both the control and the
* dropdown panel are passed in — checking one alone would close the menu the
* instant you clicked inside it.
*/
export function useClickOutside(
elements: RefObject<HTMLElement | null>[],
callback: (event: MouseEvent) => void,
enabled = true,
): void {
useEffect(() => {
if (!enabled) return
const handleClickOutside = (event: MouseEvent) => {
const isOutside = elements.every(
(ref) => !ref.current || !ref.current.contains(event.target as Node),
)
if (isOutside) callback(event)
}
document.addEventListener('mousedown', handleClickOutside)
return () => document.removeEventListener('mousedown', handleClickOutside)
}, [elements, callback, enabled])
}
+101
View File
@@ -0,0 +1,101 @@
import { useCallback, useEffect, useState, type RefObject } from 'react'
export type DropdownPlacement = 'auto' | 'up' | 'down'
export type DropdownPosition = {
top?: number
bottom?: number
left: number
width: number
maxHeight: string
}
const STANDARD_MAX_HEIGHT = 240
const BUFFER = 12
/**
* Fixed-position coordinates for a portalled dropdown.
*
* Ported from the source app's `useDropdownPosition`. The menu is rendered into
* `document.body` so it escapes any `overflow: hidden` ancestor, which means its
* position has to be measured rather than flowed.
*
* `placement: 'auto'` opens upward when there is not enough room below and more
* room above.
*/
export function useDropdownPosition(
isOpen: boolean,
containerRef: RefObject<HTMLElement | null>,
options: { placement?: DropdownPlacement } = {},
): {
dropdownPosition: DropdownPosition
calculateInitialPosition: () => void
} {
const { placement = 'auto' } = options
const [dropdownPosition, setDropdownPosition] = useState<DropdownPosition>({
left: 0,
width: 0,
maxHeight: `${STANDARD_MAX_HEIGHT}px`,
})
const measure = useCallback(() => {
const node = containerRef.current
if (!node) return
const rect = node.getBoundingClientRect()
const spaceAbove = rect.top
const spaceBelow = window.innerHeight - rect.bottom
const shouldOpenUp =
placement === 'up' ||
(placement === 'auto' &&
spaceBelow < STANDARD_MAX_HEIGHT + BUFFER &&
spaceAbove > spaceBelow)
if (shouldOpenUp) {
const available = Math.max(spaceAbove - BUFFER, 50)
setDropdownPosition({
bottom: window.innerHeight - rect.top + 4,
left: rect.left,
width: rect.width,
maxHeight: `${Math.min(STANDARD_MAX_HEIGHT, available)}px`,
})
} else {
const available = Math.max(spaceBelow - BUFFER, 50)
setDropdownPosition({
top: rect.bottom + 4,
left: rect.left,
width: rect.width,
maxHeight: `${Math.min(STANDARD_MAX_HEIGHT, available)}px`,
})
}
}, [containerRef, placement])
/**
* Measure on a frame boundary, not synchronously.
*
* The panel is portalled to `document.body` and the control's ref is not yet
* attached at the moment the dropdown is switched on, so a synchronous read
* gets nothing and leaves the panel at its zero-initialised position —
* rendered off-screen at `left: 0; width: 0` while every DOM query still
* "succeeds". Measuring after layout also picks up a control that moves
* between the click and the paint.
*/
const calculateInitialPosition = useCallback(() => {
requestAnimationFrame(() => measure())
}, [measure])
useEffect(() => {
if (!isOpen) return
const reposition = () => measure()
reposition()
window.addEventListener('resize', reposition)
window.addEventListener('scroll', reposition, true)
return () => {
window.removeEventListener('resize', reposition)
window.removeEventListener('scroll', reposition, true)
}
}, [isOpen, measure])
return { dropdownPosition, calculateInitialPosition }
}