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,113 @@
|
||||
import { forwardRef, type HTMLAttributes, type ReactNode } from 'react'
|
||||
import { cn } from '@/lib/cn'
|
||||
import {
|
||||
BADGE_COLORS,
|
||||
BADGE_COLOR_ALIAS,
|
||||
BADGE_POSITIONS,
|
||||
BADGE_ROUNDED,
|
||||
BADGE_SIZES,
|
||||
DEFAULT_BADGE_SIZES,
|
||||
resolveBadgeColor,
|
||||
type BadgeBorder,
|
||||
type BadgeColor,
|
||||
type BadgeDefaultSize,
|
||||
type BadgeFloatingPosition,
|
||||
type BadgeFloatingSize,
|
||||
type BadgeType,
|
||||
type ColorRange,
|
||||
} from './badge.tokens'
|
||||
|
||||
/**
|
||||
* Status indicator / count badge.
|
||||
*
|
||||
* Ported from the original `Badge` component.
|
||||
*
|
||||
* Two shapes:
|
||||
* - `floating` (default) — pins the badge to a corner of its child (an icon or
|
||||
* avatar), so the child wraps it.
|
||||
* - `default` — a standalone inline chip.
|
||||
*
|
||||
* `colorRanges` maps a numeric `content` onto a colour band, which is how the
|
||||
* source app colours pending-approval counts without a per-row className.
|
||||
*/
|
||||
|
||||
export type BadgeProps = Omit<HTMLAttributes<HTMLDivElement>, 'content'> & {
|
||||
type?: BadgeType
|
||||
/** The count or label. Accepts a number — counts arrive as numbers in the source app. */
|
||||
content?: ReactNode | number
|
||||
color?: BadgeColor | string
|
||||
/** Colour the badge by numeric value, e.g. `[{min:5,max:9,color:'warning'}]`. */
|
||||
colorRanges?: ColorRange[]
|
||||
floatingPosition?: BadgeFloatingPosition
|
||||
floatingSize?: BadgeFloatingSize
|
||||
defaultSize?: BadgeDefaultSize
|
||||
defaultBorder?: BadgeBorder
|
||||
/** Remix-icon class name, e.g. `"ri-home-line"`. Needs the Remix font. */
|
||||
defaultIcon?: string
|
||||
pulse?: boolean
|
||||
}
|
||||
|
||||
export const Badge = forwardRef<HTMLDivElement, BadgeProps>(function Badge(
|
||||
{
|
||||
type = 'floating',
|
||||
content,
|
||||
color = 'danger',
|
||||
colorRanges,
|
||||
children,
|
||||
floatingPosition = 'top_right',
|
||||
floatingSize = 'sm',
|
||||
pulse = false,
|
||||
className = '',
|
||||
defaultSize = 'sm',
|
||||
defaultBorder = 'lg',
|
||||
defaultIcon,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
const normalized = BADGE_COLOR_ALIAS[color] ?? (color as BadgeColor)
|
||||
const computed =
|
||||
type === 'floating' ? resolveBadgeColor(color, content, colorRanges) : normalized
|
||||
const theme = BADGE_COLORS[computed] ?? BADGE_COLORS[normalized] ?? BADGE_COLORS.danger
|
||||
|
||||
if (type === 'default') {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'inline-flex items-center justify-center font-medium transition-colors',
|
||||
BADGE_ROUNDED[defaultBorder] ?? BADGE_ROUNDED.lg,
|
||||
DEFAULT_BADGE_SIZES[defaultSize] ?? DEFAULT_BADGE_SIZES.sm,
|
||||
theme,
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{defaultIcon && <i className={cn(defaultIcon, 'mr-1.5')} aria-hidden="true" />}
|
||||
{children ?? content}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="relative inline-flex">
|
||||
{children}
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'absolute z-10 inline-flex items-center justify-center rounded-full font-semibold',
|
||||
BADGE_POSITIONS[floatingPosition] ?? BADGE_POSITIONS.top_right,
|
||||
BADGE_SIZES[floatingSize] ?? BADGE_SIZES.sm,
|
||||
theme,
|
||||
pulse && 'animate-pulse',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
</span>
|
||||
)
|
||||
})
|
||||
|
||||
export default Badge
|
||||
Reference in new issue
Block a user