@leitware/composables 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { AlertTriangleIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon } from 'lucide-react'
2
+ import type { VariantProps } from 'class-variance-authority'
2
3
  import type * as React from 'react'
3
4
 
4
5
  import {
@@ -6,10 +7,14 @@ import {
6
7
  AlertDescription,
7
8
  Alert as AlertPrimitive,
8
9
  AlertTitle,
10
+ type alertVariants,
9
11
  } from '../_internal/alert'
10
12
 
11
13
  export type AlertType = 'notice' | 'negative' | 'positive' | 'default' | 'warning'
12
14
 
15
+ /** Visual style variants available for the Alert. */
16
+ export type AlertVariant = NonNullable<VariantProps<typeof alertVariants>['variant']>
17
+
13
18
  /**
14
19
  * Props for the opinionated Alert component.
15
20
  *
@@ -21,15 +26,13 @@ export type AlertType = 'notice' | 'negative' | 'positive' | 'default' | 'warnin
21
26
  * <Alert type="positive" title="Payment successful" message="Your invoice has been sent." />
22
27
  * <Alert type="negative" title="Something went wrong" message={error.message} />
23
28
  * <Alert type="notice" message="Your session expires in 5 minutes." />
29
+ * <Alert variant="brand" title="New feature" message="Try it today." />
24
30
  * <Alert type="warning" title="Storage almost full">
25
31
  * <Button size="sm">Upgrade plan</Button>
26
32
  * </Alert>
27
33
  * ```
28
34
  */
29
- export interface AlertProps extends Omit<
30
- React.ComponentProps<typeof AlertPrimitive>,
31
- 'variant' | 'title'
32
- > {
35
+ export interface AlertProps extends Omit<React.ComponentProps<typeof AlertPrimitive>, 'title'> {
33
36
  /**
34
37
  * Semantic type that controls the icon and colour variant.
35
38
  * - `default` — no icon, neutral styling
@@ -40,6 +43,10 @@ export interface AlertProps extends Omit<
40
43
  * @default 'default'
41
44
  */
42
45
  type?: AlertType
46
+ /**
47
+ * Visual style override. When omitted, the variant is derived from `type`.
48
+ */
49
+ variant?: AlertVariant
43
50
  /** Alert heading rendered in bold. */
44
51
  title?: React.ReactNode
45
52
  /** Alert body text. Alternatively pass `children`. */
@@ -57,10 +64,17 @@ function Alert({
57
64
  children,
58
65
  action,
59
66
  className,
67
+ variant,
60
68
  ...alertProps
61
69
  }: AlertProps) {
62
- // Map alert types to variants
63
- const variant = type === 'negative' ? 'destructive' : type === 'warning' ? 'warning' : 'default'
70
+ const typeVariants: Record<AlertType, AlertVariant> = {
71
+ default: 'default',
72
+ negative: 'destructive',
73
+ notice: 'info',
74
+ positive: 'success',
75
+ warning: 'warning',
76
+ }
77
+ const resolvedVariant = variant ?? typeVariants[type]
64
78
 
65
79
  // Get icon based on type
66
80
  const getIcon = () => {
@@ -82,7 +96,7 @@ function Alert({
82
96
  const content = message || children
83
97
 
84
98
  return (
85
- <AlertPrimitive variant={variant} className={className} {...alertProps}>
99
+ <AlertPrimitive variant={resolvedVariant} className={className} {...alertProps}>
86
100
  {icon}
87
101
  <div className="flex-1">
88
102
  {title && <AlertTitle>{title}</AlertTitle>}
@@ -18,13 +18,28 @@ import { Badge as BadgePrimitive, type badgeVariants } from '../_internal/badge'
18
18
  export interface BadgeProps extends Omit<useRender.ComponentProps<'span'>, 'size'> {
19
19
  /** Visual style variant. @default 'default' */
20
20
  variant?: VariantProps<typeof badgeVariants>['variant']
21
+ /** Corner shape. 'pill' forces full rounding regardless of theme. @default 'default' */
22
+ shape?: VariantProps<typeof badgeVariants>['shape']
21
23
  className?: string
22
24
  children: React.ReactNode
23
25
  }
24
26
 
25
- function Badge({ variant = 'default', className, children, render, ...badgeProps }: BadgeProps) {
27
+ function Badge({
28
+ variant = 'default',
29
+ shape = 'default',
30
+ className,
31
+ children,
32
+ render,
33
+ ...badgeProps
34
+ }: BadgeProps) {
26
35
  return (
27
- <BadgePrimitive variant={variant} className={className} render={render} {...badgeProps}>
36
+ <BadgePrimitive
37
+ variant={variant}
38
+ shape={shape}
39
+ className={className}
40
+ render={render}
41
+ {...badgeProps}
42
+ >
28
43
  {children}
29
44
  </BadgePrimitive>
30
45
  )
@@ -20,6 +20,8 @@ export interface ButtonProps extends Omit<React.ComponentProps<'button'>, 'size'
20
20
  variant?: VariantProps<typeof buttonVariants>['variant']
21
21
  /** Size variant. @default 'default' */
22
22
  size?: VariantProps<typeof buttonVariants>['size']
23
+ /** Corner shape. 'pill' is fully rounded — circular for icon sizes. @default 'default' */
24
+ shape?: VariantProps<typeof buttonVariants>['shape']
23
25
  className?: string
24
26
  /** Disables the button and prevents interaction. @default false */
25
27
  disabled?: boolean
@@ -33,6 +35,7 @@ export interface ButtonProps extends Omit<React.ComponentProps<'button'>, 'size'
33
35
  function Button({
34
36
  variant = 'default',
35
37
  size = 'default',
38
+ shape = 'default',
36
39
  className,
37
40
  disabled = false,
38
41
  loading = false,
@@ -46,6 +49,7 @@ function Button({
46
49
  <ButtonPrimitive
47
50
  variant={variant}
48
51
  size={size}
52
+ shape={shape}
49
53
  className={className}
50
54
  disabled={isDisabled}
51
55
  type={type}
@@ -1,5 +1,12 @@
1
1
  import type { Tabs as TabsPrimitiveBase } from '@base-ui/react/tabs'
2
- import { TabsList, Tabs as TabsPrimitive, TabsTrigger } from '../_internal/tabs'
2
+ import type { VariantProps } from 'class-variance-authority'
3
+
4
+ import {
5
+ TabsList,
6
+ Tabs as TabsPrimitive,
7
+ TabsTrigger,
8
+ type tabsListVariants,
9
+ } from '../_internal/tabs'
3
10
 
4
11
  /** A single tab in the Tabs navigation bar. */
5
12
  export type TabItem = {
@@ -9,6 +16,9 @@ export type TabItem = {
9
16
  label: string
10
17
  }
11
18
 
19
+ /** Visual style variants available for the Tabs navigation bar. */
20
+ export type TabsVariant = NonNullable<VariantProps<typeof tabsListVariants>['variant']>
21
+
12
22
  /**
13
23
  * Props for the opinionated Tabs component.
14
24
  *
@@ -31,7 +41,7 @@ export type TabItem = {
31
41
  * <TabsContent value="settings">...</TabsContent>
32
42
  * ```
33
43
  */
34
- type TabsProps = Omit<TabsPrimitiveBase.Root.Props, 'children'> & {
44
+ export type TabsProps = Omit<TabsPrimitiveBase.Root.Props, 'children'> & {
35
45
  /** Tab definitions to render in the navigation bar. */
36
46
  items: TabItem[]
37
47
  /** Currently active tab value. */
@@ -40,6 +50,8 @@ type TabsProps = Omit<TabsPrimitiveBase.Root.Props, 'children'> & {
40
50
  onValueChange: (value: string) => void
41
51
  /** Accessible label for the tab list (for screen readers). */
42
52
  ariaLabel?: string
53
+ /** Visual style of the tab list. @default 'line' */
54
+ variant?: TabsVariant
43
55
  className?: string
44
56
  }
45
57
 
@@ -48,12 +60,13 @@ export const Tabs = ({
48
60
  value,
49
61
  onValueChange,
50
62
  ariaLabel,
63
+ variant = 'line',
51
64
  className,
52
65
  ...tabsProps
53
66
  }: TabsProps) => {
54
67
  return (
55
68
  <TabsPrimitive value={value} onValueChange={onValueChange} className={className} {...tabsProps}>
56
- <TabsList variant="line" aria-label={ariaLabel}>
69
+ <TabsList variant={variant} aria-label={ariaLabel}>
57
70
  {items.map((item) => (
58
71
  <TabsTrigger key={item.value} value={item.value}>
59
72
  {item.label}