@meith/ui 0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@meith/ui",
3
+ "version": "0.1.0",
4
+ "description": "Meith's shared UI primitives: buttons, menus and the class utilities themes build with.",
5
+ "license": "LGPL-3.0-or-later",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/meith-dev/meith.git",
9
+ "directory": "packages/ui"
10
+ },
11
+ "type": "module",
12
+ "main": "./src/index.ts",
13
+ "types": "./src/index.ts",
14
+ "exports": {
15
+ ".": "./src/index.ts",
16
+ "./button": "./src/button.tsx",
17
+ "./menu": "./src/menu.tsx",
18
+ "./utils": "./src/utils.ts",
19
+ "./variants": "./src/variants.ts"
20
+ },
21
+ "files": [
22
+ "src",
23
+ "!src/**/*.test.*",
24
+ "!src/**/*.type-test.*"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "dependencies": {
30
+ "@base-ui/react": "^1.5.0",
31
+ "class-variance-authority": "^0.7.1",
32
+ "clsx": "^2.1.1",
33
+ "tailwind-merge": "^3.4.1"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^19.2.0",
37
+ "react-dom": "^19.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/react": "^19.2.3",
41
+ "@types/react-dom": "^19.2.3"
42
+ }
43
+ }
package/src/alert.tsx ADDED
@@ -0,0 +1,59 @@
1
+ import { cva, type VariantProps } from 'class-variance-authority'
2
+
3
+ import { cn } from './utils'
4
+
5
+ const alertVariants = cva(
6
+ 'flex w-full items-start justify-between gap-4 rounded-md border border-l-4 px-4 py-3 text-sm',
7
+ {
8
+ variants: {
9
+ tone: {
10
+ info: 'border-border border-l-muted-foreground bg-card text-card-foreground',
11
+ success: 'border-border border-l-moderation-approved bg-card text-card-foreground',
12
+ warning: 'border-border border-l-moderation-pending bg-card text-card-foreground',
13
+ error: 'border-destructive/30 border-l-destructive bg-destructive/5 text-card-foreground',
14
+ },
15
+ },
16
+ defaultVariants: { tone: 'info' },
17
+ },
18
+ )
19
+
20
+ export type AlertTone = NonNullable<VariantProps<typeof alertVariants>['tone']>
21
+
22
+ function Alert({
23
+ className,
24
+ tone = 'info',
25
+ role,
26
+ ...props
27
+ }: React.ComponentProps<'div'> & { tone?: AlertTone }) {
28
+ return (
29
+ <div
30
+ data-slot="alert"
31
+ data-tone={tone}
32
+ role={role ?? (tone === 'error' ? 'alert' : 'status')}
33
+ className={cn(alertVariants({ tone }), className)}
34
+ {...props}
35
+ />
36
+ )
37
+ }
38
+
39
+ function AlertTitle({ className, ...props }: React.ComponentProps<'strong'>) {
40
+ return (
41
+ <strong
42
+ data-slot="alert-title"
43
+ className={cn('font-semibold text-foreground', className)}
44
+ {...props}
45
+ />
46
+ )
47
+ }
48
+
49
+ function AlertDescription({ className, ...props }: React.ComponentProps<'div'>) {
50
+ return (
51
+ <div
52
+ data-slot="alert-description"
53
+ className={cn('min-w-0 [&_a]:underline [&_a]:underline-offset-2', className)}
54
+ {...props}
55
+ />
56
+ )
57
+ }
58
+
59
+ export { Alert, AlertDescription, AlertTitle, alertVariants }
package/src/avatar.tsx ADDED
@@ -0,0 +1,46 @@
1
+ import { cn } from './utils'
2
+
3
+ export interface AvatarProps extends Omit<React.ComponentProps<'span'>, 'children'> {
4
+ readonly src?: string | null
5
+ readonly name: string
6
+ readonly size?: number
7
+ }
8
+
9
+ function Avatar({ className, src = null, name, size = 40, ...props }: AvatarProps) {
10
+ const initial = (Array.from(name.trim())[0] ?? '?').toUpperCase()
11
+
12
+ return (
13
+ <span
14
+ data-slot="avatar"
15
+ aria-hidden="true"
16
+ className={cn(
17
+ 'inline-flex shrink-0 select-none items-center justify-center overflow-hidden rounded-md border border-border bg-muted',
18
+ className,
19
+ )}
20
+ style={{ width: size, height: size }}
21
+ {...props}
22
+ >
23
+ {src === null ? (
24
+ <span
25
+ className="font-medium text-muted-foreground"
26
+ style={{ fontSize: Math.round(size * 0.42) }}
27
+ >
28
+ {initial}
29
+ </span>
30
+ ) : (
31
+ <img
32
+ src={src}
33
+ alt=""
34
+ width={size}
35
+ height={size}
36
+ loading="lazy"
37
+ decoding="async"
38
+ referrerPolicy="no-referrer"
39
+ className="size-full object-cover"
40
+ />
41
+ )}
42
+ </span>
43
+ )
44
+ }
45
+
46
+ export { Avatar }
package/src/badge.tsx ADDED
@@ -0,0 +1,8 @@
1
+ import { cn } from './utils'
2
+ import { badgeVariants, type BadgeVariants } from './variants'
3
+
4
+ function Badge({ className, tone, ...props }: React.ComponentProps<'span'> & BadgeVariants) {
5
+ return <span data-slot="badge" className={cn(badgeVariants({ tone }), className)} {...props} />
6
+ }
7
+
8
+ export { Badge }
package/src/button.tsx ADDED
@@ -0,0 +1,20 @@
1
+ 'use client'
2
+
3
+ import { Button as ButtonPrimitive } from '@base-ui/react/button'
4
+
5
+ import { cn } from './utils'
6
+ import { buttonVariants, type ButtonVariants } from './variants'
7
+
8
+ export type ButtonProps = ButtonPrimitive.Props & ButtonVariants
9
+
10
+ function Button({ className, variant, size, ...props }: ButtonProps) {
11
+ return (
12
+ <ButtonPrimitive
13
+ data-slot="button"
14
+ className={cn(buttonVariants({ variant, size }), className)}
15
+ {...props}
16
+ />
17
+ )
18
+ }
19
+
20
+ export { Button }
package/src/card.tsx ADDED
@@ -0,0 +1,97 @@
1
+ import { cn } from './utils'
2
+
3
+ type CardElement = 'section' | 'article' | 'div'
4
+
5
+ export interface CardProps extends React.ComponentProps<'section'> {
6
+ readonly as?: CardElement
7
+ }
8
+
9
+ function Card({ as = 'section', className, ...props }: CardProps) {
10
+ const Component = as as React.ElementType
11
+
12
+ return (
13
+ <Component
14
+ data-slot="card"
15
+ className={cn(
16
+ 'overflow-hidden rounded-lg border border-border bg-card text-card-foreground shadow-elevation',
17
+ className,
18
+ )}
19
+ {...props}
20
+ />
21
+ )
22
+ }
23
+
24
+ function CardHeader({ className, ...props }: React.ComponentProps<'div'>) {
25
+ return (
26
+ <div
27
+ data-slot="card-header"
28
+ className={cn(
29
+ 'flex flex-wrap items-center justify-between gap-x-4 gap-y-1 border-b border-border bg-surface px-4 py-2.5',
30
+ className,
31
+ )}
32
+ {...props}
33
+ />
34
+ )
35
+ }
36
+
37
+ function CardTitle({ className, ...props }: React.ComponentProps<'h2'>) {
38
+ return (
39
+ <h2
40
+ data-slot="card-title"
41
+ className={cn('text-base font-semibold tracking-tight text-foreground', className)}
42
+ {...props}
43
+ />
44
+ )
45
+ }
46
+
47
+ function CardDescription({ className, ...props }: React.ComponentProps<'p'>) {
48
+ return (
49
+ <p
50
+ data-slot="card-description"
51
+ className={cn('text-sm text-muted-foreground', className)}
52
+ {...props}
53
+ />
54
+ )
55
+ }
56
+
57
+ function CardAction({ className, ...props }: React.ComponentProps<'div'>) {
58
+ return (
59
+ <div
60
+ data-slot="card-action"
61
+ className={cn('flex shrink-0 flex-wrap items-center gap-2', className)}
62
+ {...props}
63
+ />
64
+ )
65
+ }
66
+
67
+ function CardContent({ className, ...props }: React.ComponentProps<'div'>) {
68
+ return <div data-slot="card-content" className={cn('px-4 py-3.5', className)} {...props} />
69
+ }
70
+
71
+ function CardRows({ className, ...props }: React.ComponentProps<'ul'>) {
72
+ return <ul data-slot="card-rows" className={cn('divide-y divide-border', className)} {...props} />
73
+ }
74
+
75
+ function CardFooter({ className, ...props }: React.ComponentProps<'div'>) {
76
+ return (
77
+ <div
78
+ data-slot="card-footer"
79
+ className={cn(
80
+ 'flex flex-wrap items-center gap-3 border-t border-border px-4 py-2.5 text-xs text-muted-foreground',
81
+ className,
82
+ )}
83
+ {...props}
84
+ />
85
+ )
86
+ }
87
+
88
+ export {
89
+ Card,
90
+ CardAction,
91
+ CardContent,
92
+ CardDescription,
93
+ CardFooter,
94
+ CardHeader,
95
+ CardRows,
96
+ CardTitle,
97
+ }
@@ -0,0 +1,59 @@
1
+ import { cn } from './utils'
2
+
3
+ export interface DisclosureProps extends Omit<React.ComponentProps<'details'>, 'children'> {
4
+ readonly summary: React.ReactNode
5
+ readonly aside?: React.ReactNode
6
+ readonly children: React.ReactNode
7
+ readonly contentClassName?: string
8
+ }
9
+
10
+ function Disclosure({
11
+ summary,
12
+ aside,
13
+ children,
14
+ className,
15
+ contentClassName,
16
+ ...props
17
+ }: DisclosureProps) {
18
+ return (
19
+ <details
20
+ data-slot="disclosure"
21
+ className={cn(
22
+ 'group overflow-hidden rounded-lg border border-border bg-card text-card-foreground',
23
+ className,
24
+ )}
25
+ {...props}
26
+ >
27
+ <summary
28
+ className={cn(
29
+ 'flex cursor-default list-none items-center gap-2 px-4 py-2.5 text-sm font-medium select-none',
30
+ 'transition-colors hover:bg-muted',
31
+ '[&::-webkit-details-marker]:hidden [&::marker]:content-none',
32
+ )}
33
+ >
34
+ <svg
35
+ aria-hidden="true"
36
+ viewBox="0 0 12 12"
37
+ className="size-3 shrink-0 text-muted-foreground transition-transform group-open:rotate-90"
38
+ fill="none"
39
+ stroke="currentColor"
40
+ strokeWidth="1.5"
41
+ strokeLinecap="round"
42
+ strokeLinejoin="round"
43
+ >
44
+ <path d="m4.5 3 3 3-3 3" />
45
+ </svg>
46
+
47
+ <span className="min-w-0 flex-1 truncate">{summary}</span>
48
+
49
+ {aside !== undefined && (
50
+ <span className="shrink-0 text-xs font-normal text-muted-foreground">{aside}</span>
51
+ )}
52
+ </summary>
53
+
54
+ <div className={cn('border-t border-border p-4', contentClassName)}>{children}</div>
55
+ </details>
56
+ )
57
+ }
58
+
59
+ export { Disclosure }
package/src/empty.tsx ADDED
@@ -0,0 +1,40 @@
1
+ import { cn } from './utils'
2
+
3
+ function Empty({ className, ...props }: React.ComponentProps<'div'>) {
4
+ return (
5
+ <div
6
+ data-slot="empty"
7
+ className={cn(
8
+ 'flex flex-col items-center gap-2 px-6 py-12 text-center text-balance',
9
+ className,
10
+ )}
11
+ {...props}
12
+ />
13
+ )
14
+ }
15
+
16
+ function EmptyTitle({ className, ...props }: React.ComponentProps<'p'>) {
17
+ return (
18
+ <p
19
+ data-slot="empty-title"
20
+ className={cn('text-sm font-medium text-foreground', className)}
21
+ {...props}
22
+ />
23
+ )
24
+ }
25
+
26
+ function EmptyDescription({ className, ...props }: React.ComponentProps<'p'>) {
27
+ return (
28
+ <p
29
+ data-slot="empty-description"
30
+ className={cn('max-w-prose text-sm text-muted-foreground', className)}
31
+ {...props}
32
+ />
33
+ )
34
+ }
35
+
36
+ function EmptyAction({ className, ...props }: React.ComponentProps<'div'>) {
37
+ return <div data-slot="empty-action" className={cn('mt-2', className)} {...props} />
38
+ }
39
+
40
+ export { Empty, EmptyAction, EmptyDescription, EmptyTitle }
package/src/field.tsx ADDED
@@ -0,0 +1,104 @@
1
+ import { cn } from './utils'
2
+
3
+ const CONTROL = [
4
+ 'w-full rounded-md border border-input bg-card px-3 text-sm text-foreground',
5
+ 'transition-[border-color,box-shadow] duration-100',
6
+ 'placeholder:text-muted-foreground',
7
+ 'disabled:cursor-not-allowed disabled:opacity-60',
8
+ 'aria-invalid:border-destructive',
9
+ ].join(' ')
10
+
11
+ function Input({ className, type = 'text', ...props }: React.ComponentProps<'input'>) {
12
+ return (
13
+ <input
14
+ data-slot="input"
15
+ type={type}
16
+ className={cn(CONTROL, 'h-9 py-1', className)}
17
+ {...props}
18
+ />
19
+ )
20
+ }
21
+
22
+ function Textarea({ className, ...props }: React.ComponentProps<'textarea'>) {
23
+ return (
24
+ <textarea
25
+ data-slot="textarea"
26
+ className={cn(CONTROL, 'min-h-32 resize-y py-2 leading-relaxed', className)}
27
+ {...props}
28
+ />
29
+ )
30
+ }
31
+
32
+ function NativeSelect({ className, ...props }: React.ComponentProps<'select'>) {
33
+ return (
34
+ <select data-slot="native-select" className={cn(CONTROL, 'h-9 pr-8', className)} {...props} />
35
+ )
36
+ }
37
+
38
+ function Label({ className, ...props }: React.ComponentProps<'label'>) {
39
+ return (
40
+ <label
41
+ data-slot="label"
42
+ className={cn('text-sm font-medium leading-none text-foreground select-none', className)}
43
+ {...props}
44
+ />
45
+ )
46
+ }
47
+
48
+ export interface FieldProps extends Omit<React.ComponentProps<'div'>, 'children' | 'id'> {
49
+ readonly name: string
50
+ readonly id?: string
51
+ readonly label: React.ReactNode
52
+ readonly description?: React.ReactNode
53
+ readonly error?: string | null
54
+ readonly children: (control: {
55
+ id: string
56
+ name: string
57
+ 'aria-describedby': string | undefined
58
+ 'aria-invalid': true | undefined
59
+ }) => React.ReactNode
60
+ }
61
+
62
+ function Field({
63
+ className,
64
+ name,
65
+ id: providedId,
66
+ label,
67
+ description,
68
+ error,
69
+ children,
70
+ ...props
71
+ }: FieldProps) {
72
+ const id = providedId ?? `field-${name}`
73
+ const descriptionId = description === undefined ? null : `${id}-description`
74
+ const errorId = error === null || error === undefined ? null : `${id}-error`
75
+
76
+ const describedBy = [errorId, descriptionId].filter((value) => value !== null).join(' ')
77
+
78
+ return (
79
+ <div data-slot="field" className={cn('flex flex-col gap-1.5', className)} {...props}>
80
+ <Label htmlFor={id}>{label}</Label>
81
+
82
+ {children({
83
+ id,
84
+ name,
85
+ 'aria-describedby': describedBy === '' ? undefined : describedBy,
86
+ 'aria-invalid': errorId === null ? undefined : true,
87
+ })}
88
+
89
+ {errorId !== null && (
90
+ <p id={errorId} className="text-xs font-medium text-destructive">
91
+ {error}
92
+ </p>
93
+ )}
94
+
95
+ {descriptionId !== null && (
96
+ <p id={descriptionId} className="text-xs text-muted-foreground">
97
+ {description}
98
+ </p>
99
+ )}
100
+ </div>
101
+ )
102
+ }
103
+
104
+ export { Field, Input, Label, NativeSelect, Textarea }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ export { cn } from './utils'
2
+
3
+ export { buttonVariants, badgeVariants } from './variants'
4
+ export type { ButtonVariants, BadgeVariants } from './variants'
5
+
6
+ export { Alert, AlertDescription, AlertTitle, alertVariants } from './alert'
7
+ export type { AlertTone } from './alert'
8
+
9
+ export { Avatar } from './avatar'
10
+ export type { AvatarProps } from './avatar'
11
+
12
+ export { Badge } from './badge'
13
+
14
+ export {
15
+ Card,
16
+ CardAction,
17
+ CardContent,
18
+ CardDescription,
19
+ CardFooter,
20
+ CardHeader,
21
+ CardRows,
22
+ CardTitle,
23
+ } from './card'
24
+ export type { CardProps } from './card'
25
+
26
+ export { Disclosure } from './disclosure'
27
+ export type { DisclosureProps } from './disclosure'
28
+
29
+ export { Empty, EmptyAction, EmptyDescription, EmptyTitle } from './empty'
30
+
31
+ export { Field, Input, Label, NativeSelect, Textarea } from './field'
32
+ export type { FieldProps } from './field'
33
+
34
+ export { Separator } from './separator'
35
+ export type { SeparatorProps } from './separator'
package/src/menu.tsx ADDED
@@ -0,0 +1,85 @@
1
+ 'use client'
2
+
3
+ import { Menu as MenuPrimitive } from '@base-ui/react/menu'
4
+
5
+ import { cn } from './utils'
6
+
7
+ export interface MenuLink {
8
+ readonly label: string
9
+ readonly href: string
10
+ }
11
+
12
+ export interface MenuProps {
13
+ readonly label: string
14
+ readonly trigger: React.ReactNode
15
+ readonly triggerClassName?: string
16
+ readonly items: readonly MenuLink[]
17
+ readonly children?: React.ReactNode
18
+ readonly align?: 'start' | 'center' | 'end'
19
+ }
20
+
21
+ function Menu({ label, trigger, triggerClassName, items, children, align = 'end' }: MenuProps) {
22
+ return (
23
+ <MenuPrimitive.Root>
24
+ <MenuPrimitive.Trigger
25
+ aria-label={label}
26
+ className={cn(
27
+ 'inline-flex cursor-default items-center gap-2 rounded-md border border-transparent px-1.5 py-1 text-sm',
28
+ 'transition-colors hover:bg-muted data-[popup-open]:bg-muted',
29
+ triggerClassName,
30
+ )}
31
+ >
32
+ {trigger}
33
+ </MenuPrimitive.Trigger>
34
+
35
+ <MenuPrimitive.Portal>
36
+ <MenuPrimitive.Positioner
37
+ align={align}
38
+ sideOffset={6}
39
+ collisionPadding={8}
40
+ className="z-50 outline-none"
41
+ >
42
+ <MenuPrimitive.Popup
43
+ className={cn(
44
+ 'min-w-52 origin-[var(--transform-origin)] overflow-hidden rounded-lg border border-border bg-card p-1 text-card-foreground shadow-lg',
45
+ 'transition-[opacity,transform] duration-100 ease-out',
46
+ 'data-[starting-style]:scale-95 data-[starting-style]:opacity-0',
47
+ 'data-[ending-style]:scale-95 data-[ending-style]:opacity-0',
48
+ )}
49
+ >
50
+ {items.map((item) => (
51
+ <MenuPrimitive.LinkItem
52
+ key={item.href}
53
+ href={item.href}
54
+ closeOnClick
55
+ className={cn(
56
+ 'flex cursor-default items-center rounded-md px-2.5 py-1.5 text-sm text-foreground outline-none select-none',
57
+ 'data-[highlighted]:bg-muted',
58
+ )}
59
+ >
60
+ {item.label}
61
+ </MenuPrimitive.LinkItem>
62
+ ))}
63
+
64
+ {children !== undefined && children !== null && (
65
+ <>
66
+ <MenuPrimitive.Separator className="-mx-1 my-1 h-px bg-border" />
67
+ <div
68
+ className={cn(
69
+ '[&_button]:flex [&_button]:w-full [&_button]:items-center [&_button]:justify-start',
70
+ '[&_button]:rounded-md [&_button]:px-2.5 [&_button]:py-1.5 [&_button]:text-sm',
71
+ '[&_button]:font-normal [&_button:hover]:bg-muted [&_button:hover]:no-underline',
72
+ )}
73
+ >
74
+ {children}
75
+ </div>
76
+ </>
77
+ )}
78
+ </MenuPrimitive.Popup>
79
+ </MenuPrimitive.Positioner>
80
+ </MenuPrimitive.Portal>
81
+ </MenuPrimitive.Root>
82
+ )
83
+ }
84
+
85
+ export { Menu }
@@ -0,0 +1,34 @@
1
+ import { cn } from './utils'
2
+
3
+ export interface SeparatorProps extends React.ComponentProps<'div'> {
4
+ readonly orientation?: 'horizontal' | 'vertical'
5
+ readonly decorative?: boolean
6
+ }
7
+
8
+ function Separator({
9
+ className,
10
+ orientation = 'horizontal',
11
+ decorative = true,
12
+ ...props
13
+ }: SeparatorProps) {
14
+ return (
15
+ <div
16
+ data-slot="separator"
17
+ data-orientation={orientation}
18
+ {...(decorative
19
+ ? { 'aria-hidden': true }
20
+ : {
21
+ role: 'separator',
22
+ ...(orientation === 'vertical' ? { 'aria-orientation': 'vertical' as const } : {}),
23
+ })}
24
+ className={cn(
25
+ 'shrink-0 bg-border',
26
+ orientation === 'horizontal' ? 'h-px w-full' : 'h-4 w-px self-center',
27
+ className,
28
+ )}
29
+ {...props}
30
+ />
31
+ )
32
+ }
33
+
34
+ export { Separator }
package/src/utils.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from 'clsx'
2
+ import { twMerge } from 'tailwind-merge'
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs))
6
+ }
@@ -0,0 +1,70 @@
1
+ import { cva, type VariantProps } from 'class-variance-authority'
2
+
3
+ export const buttonVariants = cva(
4
+ [
5
+ 'inline-flex shrink-0 select-none items-center justify-center gap-2 whitespace-nowrap',
6
+ 'rounded-md border text-sm font-medium leading-none',
7
+ 'transition-[color,background-color,border-color,opacity] duration-100 ease-out',
8
+ 'disabled:pointer-events-none disabled:opacity-50',
9
+ 'aria-disabled:pointer-events-none aria-disabled:opacity-50',
10
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
11
+ ],
12
+ {
13
+ variants: {
14
+ variant: {
15
+ primary: 'border-transparent bg-primary text-primary-foreground hover:bg-primary-hover',
16
+ secondary:
17
+ 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/70',
18
+ outline: 'border-border bg-card text-foreground hover:bg-muted',
19
+ ghost:
20
+ 'border-transparent bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground',
21
+ destructive:
22
+ 'border-destructive/30 bg-destructive/10 text-destructive hover:bg-destructive/20',
23
+ link: 'h-auto border-transparent p-0 text-foreground underline underline-offset-4 decoration-border hover:decoration-current',
24
+ },
25
+ size: {
26
+ sm: 'h-8 gap-1.5 px-2.5 text-xs',
27
+ default: 'h-9 px-3.5',
28
+ lg: 'h-10 px-4',
29
+ icon: 'size-9 p-0',
30
+ },
31
+ },
32
+ defaultVariants: { variant: 'secondary', size: 'default' },
33
+ },
34
+ )
35
+
36
+ export type ButtonVariants = VariantProps<typeof buttonVariants>
37
+
38
+ export const badgeVariants = cva(
39
+ [
40
+ 'inline-flex w-fit shrink-0 items-center gap-1 whitespace-nowrap',
41
+ 'rounded-sm border px-1.5 py-0.5 text-[0.6875rem] font-medium leading-4 tracking-wide',
42
+ "[&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-3",
43
+ ],
44
+ {
45
+ variants: {
46
+ tone: {
47
+ neutral: 'border-border bg-muted text-muted-foreground',
48
+ solid: 'border-transparent bg-primary text-primary-foreground',
49
+ outline: 'border-border bg-transparent text-foreground',
50
+ pinned: 'border-thread-pinned/30 bg-thread-pinned/10 text-thread-pinned',
51
+ locked: 'border-thread-locked/30 bg-thread-locked/10 text-thread-locked',
52
+ moved: 'border-thread-moved/30 bg-thread-moved/10 text-thread-moved',
53
+ unapproved: 'border-thread-unapproved/30 bg-thread-unapproved/10 text-thread-unapproved',
54
+ deleted: 'border-thread-deleted/30 bg-thread-deleted/10 text-thread-deleted',
55
+ pending: 'border-moderation-pending/30 bg-moderation-pending/10 text-moderation-pending',
56
+ approved:
57
+ 'border-moderation-approved/30 bg-moderation-approved/10 text-moderation-approved',
58
+ rejected:
59
+ 'border-moderation-rejected/30 bg-moderation-rejected/10 text-moderation-rejected',
60
+ admin: 'border-group-admin/30 bg-group-admin/10 text-group-admin',
61
+ supermod: 'border-group-supermod/30 bg-group-supermod/10 text-group-supermod',
62
+ mod: 'border-group-mod/30 bg-group-mod/10 text-group-mod',
63
+ banned: 'border-group-banned/30 bg-group-banned/10 text-group-banned',
64
+ },
65
+ },
66
+ defaultVariants: { tone: 'neutral' },
67
+ },
68
+ )
69
+
70
+ export type BadgeVariants = VariantProps<typeof badgeVariants>