@strategicos/ui 0.2.0 → 0.4.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/README.md +22 -1
- package/dist/components/alert.d.ts +1 -1
- package/dist/components/alert.d.ts.map +1 -1
- package/dist/components/alert.js +10 -6
- package/dist/components/alert.js.map +1 -1
- package/dist/components/badge.d.ts +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/card.js +4 -4
- package/dist/components/card.js.map +1 -1
- package/dist/components/checkbox.d.ts +8 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +13 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/field.d.ts +27 -0
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +38 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/input.d.ts +16 -2
- package/dist/components/input.d.ts.map +1 -1
- package/dist/components/input.js +14 -4
- package/dist/components/input.js.map +1 -1
- package/dist/components/pagination.d.ts.map +1 -1
- package/dist/components/pagination.js +16 -2
- package/dist/components/pagination.js.map +1 -1
- package/dist/components/password-input.d.ts +8 -0
- package/dist/components/password-input.d.ts.map +1 -0
- package/dist/components/password-input.js +14 -0
- package/dist/components/password-input.js.map +1 -0
- package/dist/components/select.d.ts.map +1 -1
- package/dist/components/select.js +2 -1
- package/dist/components/select.js.map +1 -1
- package/dist/components/switch.d.ts +8 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +12 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/table.js +2 -2
- package/dist/components/table.js.map +1 -1
- package/dist/components/textarea.d.ts +9 -3
- package/dist/components/textarea.d.ts.map +1 -1
- package/dist/components/textarea.js +11 -4
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/tooltip.js +1 -1
- package/package.json +1 -1
- package/src/components/alert.tsx +10 -7
- package/src/components/badge.tsx +1 -1
- package/src/components/card.tsx +4 -4
- package/src/components/checkbox.tsx +33 -0
- package/src/components/field.tsx +119 -0
- package/src/components/input.tsx +48 -8
- package/src/components/pagination.tsx +54 -18
- package/src/components/password-input.tsx +35 -0
- package/src/components/select.tsx +3 -2
- package/src/components/switch.tsx +32 -0
- package/src/components/table.tsx +2 -2
- package/src/components/textarea.tsx +18 -5
- package/src/components/tooltip.tsx +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../src/components/textarea.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../src/components/textarea.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B;;;;;;;;;;;;;;GAcG;AACH,iBAAS,QAAQ,CAAC,EAChB,SAAS,EACT,QAAgB,EAChB,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,qBAa3D;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { useFieldControl } from "./field.js";
|
|
3
5
|
/**
|
|
4
6
|
* Campo multilinha. Espelha os tokens do <Input> — mesma borda, mesmo raio,
|
|
5
|
-
* mesmo
|
|
6
|
-
*
|
|
7
|
+
* mesmo foco, mesmo tratamento de desabilitado e de aria-invalid — para que um
|
|
8
|
+
* campo de texto longo não pareça de outro sistema ao lado de um curto.
|
|
7
9
|
*
|
|
8
10
|
* Difere do Input só no que a multilinha exige: sem altura fixa, com padding
|
|
9
11
|
* vertical maior e `leading-relaxed`.
|
|
10
12
|
*
|
|
13
|
+
* `autosize`: a altura acompanha o texto (CSS `field-sizing: content`, sem
|
|
14
|
+
* JS). Limite a altura com `max-h-*` no className. Navegadores sem suporte
|
|
15
|
+
* (Firefox, hoje) mantêm a altura de `rows`.
|
|
16
|
+
*
|
|
11
17
|
* Não confundir com o InlineTextarea do gerenciador: aquele é um editor inline
|
|
12
18
|
* (sem borda até o hover, salva no blur), um padrão deliberadamente diferente.
|
|
13
19
|
*/
|
|
14
|
-
function Textarea({ className, ...props }) {
|
|
15
|
-
|
|
20
|
+
function Textarea({ className, autosize = false, ...props }) {
|
|
21
|
+
const controlProps = useFieldControl(props);
|
|
22
|
+
return (_jsx("textarea", { "data-slot": "textarea", className: cn("w-full min-w-0 resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-base leading-relaxed transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 aria-invalid:border-destructive aria-invalid:text-destructive aria-invalid:placeholder:text-destructive/60 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80", autosize && "field-sizing-content min-h-16 overflow-y-auto", className), ...controlProps }));
|
|
16
23
|
}
|
|
17
24
|
export { Textarea };
|
|
18
25
|
//# sourceMappingURL=textarea.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../src/components/textarea.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../src/components/textarea.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAIZ,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;;;;;;;;;;GAcG;AACH,SAAS,QAAQ,CAAC,EAChB,SAAS,EACT,QAAQ,GAAG,KAAK,EAChB,GAAG,KAAK,EACkD;IAC1D,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IAC3C,OAAO,CACL,gCACY,UAAU,EACpB,SAAS,EAAE,EAAE,CACX,4aAA4a,EAC5a,QAAQ,IAAI,+CAA+C,EAC3D,SAAS,CACV,KACG,YAAY,GAChB,CACH,CAAA;AACH,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -12,7 +12,7 @@ function TooltipTrigger({ ...props }) {
|
|
|
12
12
|
return _jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
|
|
13
13
|
}
|
|
14
14
|
function TooltipContent({ className, sideOffset = 0, children, ...props }) {
|
|
15
|
-
return (_jsx(TooltipPrimitive.Portal, { children: _jsxs(TooltipPrimitive.Content, { "data-slot": "tooltip-content", sideOffset: sideOffset, className: cn("z-50 inline-flex w-fit max-w-xs origin-(--radix-tooltip-content-transform-origin) items-center gap-1.5 rounded-
|
|
15
|
+
return (_jsx(TooltipPrimitive.Portal, { children: _jsxs(TooltipPrimitive.Content, { "data-slot": "tooltip-content", sideOffset: sideOffset, className: cn("z-50 inline-flex w-fit max-w-xs origin-(--radix-tooltip-content-transform-origin) items-center gap-1.5 rounded-lg bg-foreground px-2.5 py-1 text-sm text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className), ...props, children: [children, _jsx(TooltipPrimitive.Arrow, { className: "z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" })] }) }));
|
|
16
16
|
}
|
|
17
17
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
18
18
|
//# sourceMappingURL=tooltip.js.map
|
package/package.json
CHANGED
package/src/components/alert.tsx
CHANGED
|
@@ -4,13 +4,16 @@ import { cva, type VariantProps } from "class-variance-authority"
|
|
|
4
4
|
import { cn } from "../lib/utils.js"
|
|
5
5
|
|
|
6
6
|
const alertVariants = cva(
|
|
7
|
-
"group/alert relative grid w-full gap-
|
|
7
|
+
"group/alert relative grid w-full gap-1 rounded-lg px-4 py-3 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-3 *:[svg]:row-span-2 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-5",
|
|
8
8
|
{
|
|
9
9
|
variants: {
|
|
10
10
|
variant: {
|
|
11
|
-
default: "bg-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
default: "bg-muted text-foreground",
|
|
12
|
+
// Status: fundo em /10 da cor; título e ícone na cor, texto neutro.
|
|
13
|
+
info: "bg-info/10 *:data-[slot=alert-title]:text-info *:[svg]:text-info",
|
|
14
|
+
success: "bg-success/10 *:data-[slot=alert-title]:text-success *:[svg]:text-success",
|
|
15
|
+
warning: "bg-warning/10 *:data-[slot=alert-title]:text-warning-strong *:[svg]:text-warning",
|
|
16
|
+
destructive: "bg-destructive/10 *:data-[slot=alert-title]:text-destructive *:[svg]:text-destructive",
|
|
14
17
|
},
|
|
15
18
|
},
|
|
16
19
|
defaultVariants: {
|
|
@@ -39,7 +42,7 @@ function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
39
42
|
<div
|
|
40
43
|
data-slot="alert-title"
|
|
41
44
|
className={cn(
|
|
42
|
-
"font-
|
|
45
|
+
"font-semibold group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",
|
|
43
46
|
className
|
|
44
47
|
)}
|
|
45
48
|
{...props}
|
|
@@ -55,7 +58,7 @@ function AlertDescription({
|
|
|
55
58
|
<div
|
|
56
59
|
data-slot="alert-description"
|
|
57
60
|
className={cn(
|
|
58
|
-
"text-sm text-balance text-
|
|
61
|
+
"text-sm text-balance text-foreground/80 md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
|
59
62
|
className
|
|
60
63
|
)}
|
|
61
64
|
{...props}
|
|
@@ -67,7 +70,7 @@ function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
67
70
|
return (
|
|
68
71
|
<div
|
|
69
72
|
data-slot="alert-action"
|
|
70
|
-
className={cn("absolute top-2 right-2", className)}
|
|
73
|
+
className={cn("absolute top-2.5 right-2.5", className)}
|
|
71
74
|
{...props}
|
|
72
75
|
/>
|
|
73
76
|
)
|
package/src/components/badge.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { Slot } from "radix-ui"
|
|
|
5
5
|
import { cn } from "../lib/utils.js"
|
|
6
6
|
|
|
7
7
|
const badgeVariants = cva(
|
|
8
|
-
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-
|
|
8
|
+
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2.5 text-[11px] font-bold tracking-[0.025em] whitespace-nowrap uppercase transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
|
|
9
9
|
{
|
|
10
10
|
variants: {
|
|
11
11
|
variant: {
|
package/src/components/card.tsx
CHANGED
|
@@ -12,7 +12,7 @@ function Card({
|
|
|
12
12
|
data-slot="card"
|
|
13
13
|
data-size={size}
|
|
14
14
|
className={cn(
|
|
15
|
-
"group/card flex flex-col gap-4 overflow-hidden rounded-
|
|
15
|
+
"group/card flex flex-col gap-4 overflow-hidden rounded-lg border border-border bg-card py-4 text-sm text-card-foreground shadow-card has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-lg *:[img:last-child]:rounded-b-lg",
|
|
16
16
|
className
|
|
17
17
|
)}
|
|
18
18
|
{...props}
|
|
@@ -25,7 +25,7 @@ function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
25
25
|
<div
|
|
26
26
|
data-slot="card-header"
|
|
27
27
|
className={cn(
|
|
28
|
-
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-
|
|
28
|
+
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-lg px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",
|
|
29
29
|
className
|
|
30
30
|
)}
|
|
31
31
|
{...props}
|
|
@@ -38,7 +38,7 @@ function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
38
38
|
<div
|
|
39
39
|
data-slot="card-title"
|
|
40
40
|
className={cn(
|
|
41
|
-
"font-heading text-base leading-snug font-
|
|
41
|
+
"font-heading text-base leading-snug font-semibold group-data-[size=sm]/card:text-sm",
|
|
42
42
|
className
|
|
43
43
|
)}
|
|
44
44
|
{...props}
|
|
@@ -84,7 +84,7 @@ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
84
84
|
<div
|
|
85
85
|
data-slot="card-footer"
|
|
86
86
|
className={cn(
|
|
87
|
-
"flex items-center rounded-b-
|
|
87
|
+
"flex items-center rounded-b-lg border-t bg-muted/50 p-4 group-data-[size=sm]/card:p-3",
|
|
88
88
|
className
|
|
89
89
|
)}
|
|
90
90
|
{...props}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Checkbox as CheckboxPrimitive } from "radix-ui"
|
|
5
|
+
import { CheckIcon, MinusIcon } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../lib/utils.js"
|
|
8
|
+
|
|
9
|
+
/** Caixa de seleção (Radix Checkbox), no tamanho padrão do Mantine: 20px,
|
|
10
|
+
* raio de 4px, marcada na cor primária. Aceita `checked="indeterminate"`.
|
|
11
|
+
* Para rótulo, associe um <Label htmlFor> ao `id` do Checkbox. */
|
|
12
|
+
function Checkbox({
|
|
13
|
+
className,
|
|
14
|
+
...props
|
|
15
|
+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
16
|
+
return (
|
|
17
|
+
<CheckboxPrimitive.Root
|
|
18
|
+
data-slot="checkbox"
|
|
19
|
+
className={cn(
|
|
20
|
+
"peer group/checkbox inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-input bg-background text-primary-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive data-checked:border-primary data-checked:bg-primary data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary dark:bg-input/30",
|
|
21
|
+
className
|
|
22
|
+
)}
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
<CheckboxPrimitive.Indicator data-slot="checkbox-indicator" className="flex items-center justify-center">
|
|
26
|
+
<CheckIcon className="size-3.5 stroke-3 group-data-[state=indeterminate]/checkbox:hidden" />
|
|
27
|
+
<MinusIcon className="hidden size-3.5 stroke-3 group-data-[state=indeterminate]/checkbox:block" />
|
|
28
|
+
</CheckboxPrimitive.Indicator>
|
|
29
|
+
</CheckboxPrimitive.Root>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { Checkbox }
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/utils.js"
|
|
6
|
+
import { Label } from "./label.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Invólucro de um campo de formulário, como o Input.Wrapper do Mantine:
|
|
10
|
+
* rótulo, descrição, o controle e a mensagem de erro, nessa ordem.
|
|
11
|
+
*
|
|
12
|
+
* O controle dentro dele (Input, Textarea, PasswordInput, SelectTrigger) é
|
|
13
|
+
* ligado automaticamente: recebe o `id` do rótulo, o `aria-describedby` com a
|
|
14
|
+
* descrição e o erro, o `aria-invalid` quando há erro e o `required`. Nada
|
|
15
|
+
* disso precisa ser repetido na tela.
|
|
16
|
+
*
|
|
17
|
+
* <Field label="E-mail" description="Usado nos avisos" error={erro} required>
|
|
18
|
+
* <Input type="email" value={email} onChange={…} />
|
|
19
|
+
* </Field>
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
type FieldContextValue = {
|
|
23
|
+
id: string
|
|
24
|
+
describedBy?: string
|
|
25
|
+
invalid: boolean
|
|
26
|
+
required: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const FieldContext = React.createContext<FieldContextValue | null>(null)
|
|
30
|
+
|
|
31
|
+
type ControlProps = {
|
|
32
|
+
id?: string
|
|
33
|
+
"aria-describedby"?: string
|
|
34
|
+
"aria-invalid"?: React.AriaAttributes["aria-invalid"]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Mescla nas props do controle o que vem do Field em volta (se houver).
|
|
38
|
+
* O que a tela passar explicitamente vence. `withRequired: false` para
|
|
39
|
+
* controles em que `required` não é atributo válido (o SelectTrigger é um
|
|
40
|
+
* <button>). */
|
|
41
|
+
function useFieldControl<P extends ControlProps & { required?: boolean }>(
|
|
42
|
+
props: P,
|
|
43
|
+
{ withRequired = true }: { withRequired?: boolean } = {}
|
|
44
|
+
): P {
|
|
45
|
+
const field = React.useContext(FieldContext)
|
|
46
|
+
if (!field) return props
|
|
47
|
+
const describedBy = [props["aria-describedby"], field.describedBy].filter(Boolean).join(" ") || undefined
|
|
48
|
+
return {
|
|
49
|
+
...props,
|
|
50
|
+
id: props.id ?? field.id,
|
|
51
|
+
"aria-describedby": describedBy,
|
|
52
|
+
"aria-invalid": props["aria-invalid"] ?? (field.invalid || undefined),
|
|
53
|
+
...(withRequired && { required: props.required ?? (field.required || undefined) }),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function Field({
|
|
58
|
+
label,
|
|
59
|
+
description,
|
|
60
|
+
error,
|
|
61
|
+
required = false,
|
|
62
|
+
id,
|
|
63
|
+
className,
|
|
64
|
+
children,
|
|
65
|
+
...props
|
|
66
|
+
}: Omit<React.ComponentProps<"div">, "id"> & {
|
|
67
|
+
label?: React.ReactNode
|
|
68
|
+
description?: React.ReactNode
|
|
69
|
+
/** Mensagem de erro. Quando presente, o controle fica com aria-invalid. */
|
|
70
|
+
error?: React.ReactNode
|
|
71
|
+
/** Mostra o asterisco no rótulo e marca o controle como obrigatório. */
|
|
72
|
+
required?: boolean
|
|
73
|
+
/** id do controle. Sem ele, um id é gerado. */
|
|
74
|
+
id?: string
|
|
75
|
+
}) {
|
|
76
|
+
const autoId = React.useId()
|
|
77
|
+
const controlId = id ?? autoId
|
|
78
|
+
const descriptionId = description ? `${controlId}-description` : undefined
|
|
79
|
+
const errorId = error ? `${controlId}-error` : undefined
|
|
80
|
+
|
|
81
|
+
const value = React.useMemo<FieldContextValue>(
|
|
82
|
+
() => ({
|
|
83
|
+
id: controlId,
|
|
84
|
+
describedBy: [descriptionId, errorId].filter(Boolean).join(" ") || undefined,
|
|
85
|
+
invalid: !!error,
|
|
86
|
+
required,
|
|
87
|
+
}),
|
|
88
|
+
[controlId, descriptionId, errorId, error, required]
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
data-slot="field"
|
|
94
|
+
data-invalid={error ? true : undefined}
|
|
95
|
+
className={cn("grid content-start gap-1.5", className)}
|
|
96
|
+
{...props}
|
|
97
|
+
>
|
|
98
|
+
{label && (
|
|
99
|
+
<Label htmlFor={controlId}>
|
|
100
|
+
{label}
|
|
101
|
+
{required && <span aria-hidden className="-ml-1 text-destructive">*</span>}
|
|
102
|
+
</Label>
|
|
103
|
+
)}
|
|
104
|
+
{description && (
|
|
105
|
+
<p id={descriptionId} data-slot="field-description" className="-mt-0.5 text-xs leading-snug text-muted-foreground">
|
|
106
|
+
{description}
|
|
107
|
+
</p>
|
|
108
|
+
)}
|
|
109
|
+
<FieldContext.Provider value={value}>{children}</FieldContext.Provider>
|
|
110
|
+
{error && (
|
|
111
|
+
<p id={errorId} data-slot="field-error" className="text-xs leading-snug text-destructive">
|
|
112
|
+
{error}
|
|
113
|
+
</p>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { Field, useFieldControl }
|
package/src/components/input.tsx
CHANGED
|
@@ -1,19 +1,59 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
1
3
|
import * as React from "react"
|
|
2
4
|
|
|
3
5
|
import { cn } from "../lib/utils.js"
|
|
6
|
+
import { useFieldControl } from "./field.js"
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
/** Classes do campo. Foco e erro seguem o Mantine: só a borda muda de cor,
|
|
9
|
+
* sem halo em volta. */
|
|
10
|
+
const inputClassName =
|
|
11
|
+
"h-9 w-full min-w-0 rounded-lg border border-input bg-transparent px-3 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 aria-invalid:border-destructive aria-invalid:text-destructive aria-invalid:placeholder:text-destructive/60 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80"
|
|
12
|
+
|
|
13
|
+
const sectionClassName =
|
|
14
|
+
"absolute inset-y-0 flex w-9 items-center justify-center text-muted-foreground [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
|
15
|
+
|
|
16
|
+
type InputProps = React.ComponentProps<"input"> & {
|
|
17
|
+
/** Conteúdo à esquerda, dentro do campo (ex.: ícone de busca). Não recebe
|
|
18
|
+
* cliques: o clique passa para o campo. */
|
|
19
|
+
leftSection?: React.ReactNode
|
|
20
|
+
/** Conteúdo à direita, dentro do campo (ex.: botão de limpar). Recebe
|
|
21
|
+
* cliques. */
|
|
22
|
+
rightSection?: React.ReactNode
|
|
23
|
+
/** Classes do invólucro, que só existe quando há seção. Use para largura e
|
|
24
|
+
* posição no layout (flex-1, w-64…); `className` vai sempre no <input>. */
|
|
25
|
+
wrapperClassName?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Input({ className, type, leftSection, rightSection, wrapperClassName, ...props }: InputProps) {
|
|
29
|
+
const controlProps = useFieldControl(props)
|
|
30
|
+
|
|
31
|
+
const input = (
|
|
7
32
|
<input
|
|
8
33
|
type={type}
|
|
9
34
|
data-slot="input"
|
|
10
|
-
className={cn(
|
|
11
|
-
|
|
12
|
-
className
|
|
13
|
-
)}
|
|
14
|
-
{...props}
|
|
35
|
+
className={cn(inputClassName, !!leftSection && "pl-9", !!rightSection && "pr-9", className)}
|
|
36
|
+
{...controlProps}
|
|
15
37
|
/>
|
|
16
38
|
)
|
|
39
|
+
|
|
40
|
+
if (!leftSection && !rightSection) return input
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div data-slot="input-wrapper" className={cn("relative w-full min-w-0", wrapperClassName)}>
|
|
44
|
+
{leftSection && (
|
|
45
|
+
<span data-slot="input-left-section" className={cn(sectionClassName, "pointer-events-none left-0")}>
|
|
46
|
+
{leftSection}
|
|
47
|
+
</span>
|
|
48
|
+
)}
|
|
49
|
+
{input}
|
|
50
|
+
{rightSection && (
|
|
51
|
+
<span data-slot="input-right-section" className={cn(sectionClassName, "right-0")}>
|
|
52
|
+
{rightSection}
|
|
53
|
+
</span>
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
)
|
|
17
57
|
}
|
|
18
58
|
|
|
19
|
-
export { Input }
|
|
59
|
+
export { Input, inputClassName, type InputProps }
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChevronLeft, ChevronRight } from "lucide-react"
|
|
2
2
|
|
|
3
3
|
import { cn } from "../lib/utils.js"
|
|
4
|
-
import { Button } from "./button.js"
|
|
5
4
|
|
|
6
5
|
interface PaginationProps {
|
|
7
6
|
page: number
|
|
@@ -13,6 +12,24 @@ interface PaginationProps {
|
|
|
13
12
|
className?: string
|
|
14
13
|
}
|
|
15
14
|
|
|
15
|
+
type Item = number | "dots"
|
|
16
|
+
|
|
17
|
+
/** Páginas visíveis, no padrão do Mantine: a primeira e a última sempre, a
|
|
18
|
+
* atual com uma vizinha de cada lado, e reticências no lugar dos buracos.
|
|
19
|
+
* O total de itens é fixo (7 quando há buraco), para os botões não pularem
|
|
20
|
+
* de posição enquanto se navega. */
|
|
21
|
+
function pageItems(page: number, totalPages: number): Item[] {
|
|
22
|
+
const range = (a: number, b: number) => Array.from({ length: b - a + 1 }, (_, i) => a + i)
|
|
23
|
+
if (totalPages <= 7) return range(1, totalPages)
|
|
24
|
+
|
|
25
|
+
if (page <= 4) return [...range(1, 5), "dots", totalPages]
|
|
26
|
+
if (page >= totalPages - 3) return [1, "dots", ...range(totalPages - 4, totalPages)]
|
|
27
|
+
return [1, "dots", page - 1, page, page + 1, "dots", totalPages]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const control =
|
|
31
|
+
"inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-border bg-background text-sm font-medium tabular-nums text-foreground transition-colors outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-background"
|
|
32
|
+
|
|
16
33
|
export function Pagination({
|
|
17
34
|
page,
|
|
18
35
|
totalPages,
|
|
@@ -28,35 +45,54 @@ export function Pagination({
|
|
|
28
45
|
const to = Math.min(page * pageSize, total)
|
|
29
46
|
|
|
30
47
|
return (
|
|
31
|
-
<div className={cn("flex items-center justify-between gap-3 pt-3", className)}>
|
|
32
|
-
<p className="text-xs text-muted-foreground">
|
|
48
|
+
<div className={cn("flex flex-wrap items-center justify-between gap-3 pt-3", className)}>
|
|
49
|
+
<p className="text-xs text-muted-foreground tabular-nums">
|
|
33
50
|
{from}–{to} de {total}
|
|
34
51
|
</p>
|
|
35
|
-
<
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
className="size-8"
|
|
52
|
+
<nav aria-label="Paginação" className="flex items-center gap-1.5">
|
|
53
|
+
<button
|
|
54
|
+
type="button"
|
|
55
|
+
className={control}
|
|
40
56
|
disabled={page <= 1 || loading}
|
|
41
57
|
onClick={() => onPageChange(page - 1)}
|
|
42
58
|
aria-label="Página anterior"
|
|
43
59
|
>
|
|
44
60
|
<ChevronLeft className="size-4" />
|
|
45
|
-
</
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
</button>
|
|
62
|
+
|
|
63
|
+
{pageItems(page, totalPages).map((item, i) =>
|
|
64
|
+
item === "dots" ? (
|
|
65
|
+
<span key={`dots-${i}`} aria-hidden className="inline-flex size-8 items-center justify-center text-sm text-muted-foreground">
|
|
66
|
+
…
|
|
67
|
+
</span>
|
|
68
|
+
) : (
|
|
69
|
+
<button
|
|
70
|
+
key={item}
|
|
71
|
+
type="button"
|
|
72
|
+
className={cn(
|
|
73
|
+
control,
|
|
74
|
+
item === page && "border-primary bg-primary text-primary-foreground hover:bg-primary-hover"
|
|
75
|
+
)}
|
|
76
|
+
disabled={loading}
|
|
77
|
+
aria-current={item === page ? "page" : undefined}
|
|
78
|
+
aria-label={`Página ${item}`}
|
|
79
|
+
onClick={() => item !== page && onPageChange(item)}
|
|
80
|
+
>
|
|
81
|
+
{item}
|
|
82
|
+
</button>
|
|
83
|
+
)
|
|
84
|
+
)}
|
|
85
|
+
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
className={control}
|
|
53
89
|
disabled={page >= totalPages || loading}
|
|
54
90
|
onClick={() => onPageChange(page + 1)}
|
|
55
91
|
aria-label="Próxima página"
|
|
56
92
|
>
|
|
57
93
|
<ChevronRight className="size-4" />
|
|
58
|
-
</
|
|
59
|
-
</
|
|
94
|
+
</button>
|
|
95
|
+
</nav>
|
|
60
96
|
</div>
|
|
61
97
|
)
|
|
62
98
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { EyeIcon, EyeOffIcon } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { Input, type InputProps } from "./input.js"
|
|
7
|
+
|
|
8
|
+
/** Campo de senha com o botão de mostrar/ocultar à direita, como o
|
|
9
|
+
* PasswordInput do Mantine. Aceita as mesmas props do Input, menos `type` e
|
|
10
|
+
* `rightSection`, que ele controla. */
|
|
11
|
+
function PasswordInput({ disabled, ...props }: Omit<InputProps, "type" | "rightSection">) {
|
|
12
|
+
const [visible, setVisible] = React.useState(false)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Input
|
|
16
|
+
{...props}
|
|
17
|
+
disabled={disabled}
|
|
18
|
+
type={visible ? "text" : "password"}
|
|
19
|
+
rightSection={
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
onClick={() => setVisible(v => !v)}
|
|
23
|
+
disabled={disabled}
|
|
24
|
+
aria-label={visible ? "Ocultar senha" : "Mostrar senha"}
|
|
25
|
+
aria-pressed={visible}
|
|
26
|
+
className="flex size-7 cursor-pointer items-center justify-center rounded-md transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50"
|
|
27
|
+
>
|
|
28
|
+
{visible ? <EyeOffIcon /> : <EyeIcon />}
|
|
29
|
+
</button>
|
|
30
|
+
}
|
|
31
|
+
/>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { PasswordInput }
|
|
@@ -4,6 +4,7 @@ import * as React from "react"
|
|
|
4
4
|
import { Select as SelectPrimitive } from "radix-ui"
|
|
5
5
|
|
|
6
6
|
import { cn } from "../lib/utils.js"
|
|
7
|
+
import { useFieldControl } from "./field.js"
|
|
7
8
|
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react"
|
|
8
9
|
|
|
9
10
|
function Select({
|
|
@@ -44,10 +45,10 @@ function SelectTrigger({
|
|
|
44
45
|
data-slot="select-trigger"
|
|
45
46
|
data-size={size}
|
|
46
47
|
className={cn(
|
|
47
|
-
"flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2.5 pl-3 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring
|
|
48
|
+
"flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2.5 pl-3 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring data-[state=open]:border-ring disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 aria-invalid:border-destructive data-placeholder:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-7.5 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
48
49
|
className
|
|
49
50
|
)}
|
|
50
|
-
{...props}
|
|
51
|
+
{...useFieldControl(props, { withRequired: false })}
|
|
51
52
|
>
|
|
52
53
|
{children}
|
|
53
54
|
<SelectPrimitive.Icon asChild>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Switch as SwitchPrimitive } from "radix-ui"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils.js"
|
|
7
|
+
|
|
8
|
+
/** Interruptor liga/desliga (Radix Switch), no tamanho padrão do Mantine:
|
|
9
|
+
* trilho de 38×20px e polegar de 14px. Ligado usa a cor primária.
|
|
10
|
+
* Para rótulo, associe um <Label htmlFor> ao `id` do Switch. */
|
|
11
|
+
function Switch({
|
|
12
|
+
className,
|
|
13
|
+
...props
|
|
14
|
+
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
|
15
|
+
return (
|
|
16
|
+
<SwitchPrimitive.Root
|
|
17
|
+
data-slot="switch"
|
|
18
|
+
className={cn(
|
|
19
|
+
"peer inline-flex h-5 w-9.5 shrink-0 cursor-pointer items-center rounded-full border border-input bg-muted p-0.5 transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-checked:border-primary data-checked:bg-primary dark:bg-input/40",
|
|
20
|
+
className
|
|
21
|
+
)}
|
|
22
|
+
{...props}
|
|
23
|
+
>
|
|
24
|
+
<SwitchPrimitive.Thumb
|
|
25
|
+
data-slot="switch-thumb"
|
|
26
|
+
className="pointer-events-none block size-3.5 rounded-full bg-background shadow-sm ring-1 ring-foreground/10 transition-transform data-checked:translate-x-4.5 data-unchecked:translate-x-0"
|
|
27
|
+
/>
|
|
28
|
+
</SwitchPrimitive.Root>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { Switch }
|
package/src/components/table.tsx
CHANGED
|
@@ -70,7 +70,7 @@ function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
|
|
70
70
|
<th
|
|
71
71
|
data-slot="table-head"
|
|
72
72
|
className={cn(
|
|
73
|
-
"h-10 px-2 text-left align-middle font-
|
|
73
|
+
"h-10 px-2.5 text-left align-middle font-bold whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
|
|
74
74
|
className
|
|
75
75
|
)}
|
|
76
76
|
{...props}
|
|
@@ -83,7 +83,7 @@ function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
|
|
83
83
|
<td
|
|
84
84
|
data-slot="table-cell"
|
|
85
85
|
className={cn(
|
|
86
|
-
"
|
|
86
|
+
"px-2.5 py-2.5 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0",
|
|
87
87
|
className
|
|
88
88
|
)}
|
|
89
89
|
{...props}
|
|
@@ -1,27 +1,40 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
1
3
|
import * as React from "react"
|
|
2
4
|
|
|
3
5
|
import { cn } from "../lib/utils.js"
|
|
6
|
+
import { useFieldControl } from "./field.js"
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Campo multilinha. Espelha os tokens do <Input> — mesma borda, mesmo raio,
|
|
7
|
-
* mesmo
|
|
8
|
-
*
|
|
10
|
+
* mesmo foco, mesmo tratamento de desabilitado e de aria-invalid — para que um
|
|
11
|
+
* campo de texto longo não pareça de outro sistema ao lado de um curto.
|
|
9
12
|
*
|
|
10
13
|
* Difere do Input só no que a multilinha exige: sem altura fixa, com padding
|
|
11
14
|
* vertical maior e `leading-relaxed`.
|
|
12
15
|
*
|
|
16
|
+
* `autosize`: a altura acompanha o texto (CSS `field-sizing: content`, sem
|
|
17
|
+
* JS). Limite a altura com `max-h-*` no className. Navegadores sem suporte
|
|
18
|
+
* (Firefox, hoje) mantêm a altura de `rows`.
|
|
19
|
+
*
|
|
13
20
|
* Não confundir com o InlineTextarea do gerenciador: aquele é um editor inline
|
|
14
21
|
* (sem borda até o hover, salva no blur), um padrão deliberadamente diferente.
|
|
15
22
|
*/
|
|
16
|
-
function Textarea({
|
|
23
|
+
function Textarea({
|
|
24
|
+
className,
|
|
25
|
+
autosize = false,
|
|
26
|
+
...props
|
|
27
|
+
}: React.ComponentProps<"textarea"> & { autosize?: boolean }) {
|
|
28
|
+
const controlProps = useFieldControl(props)
|
|
17
29
|
return (
|
|
18
30
|
<textarea
|
|
19
31
|
data-slot="textarea"
|
|
20
32
|
className={cn(
|
|
21
|
-
"w-full min-w-0 resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-base leading-relaxed transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring
|
|
33
|
+
"w-full min-w-0 resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-base leading-relaxed transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 aria-invalid:border-destructive aria-invalid:text-destructive aria-invalid:placeholder:text-destructive/60 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80",
|
|
34
|
+
autosize && "field-sizing-content min-h-16 overflow-y-auto",
|
|
22
35
|
className
|
|
23
36
|
)}
|
|
24
|
-
{...
|
|
37
|
+
{...controlProps}
|
|
25
38
|
/>
|
|
26
39
|
)
|
|
27
40
|
}
|