@mbao01/common 0.0.7 → 0.0.9

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.
Files changed (149) hide show
  1. package/dist/types/components/Avatar/types.d.ts +1 -0
  2. package/dist/types/components/Badge/types.d.ts +1 -0
  3. package/dist/types/components/Breadcrumbs/types.d.ts +1 -0
  4. package/dist/types/components/Button/Button.d.ts +7 -7
  5. package/dist/types/components/Combobox/Combobox.d.ts +2 -0
  6. package/dist/types/components/Combobox/index.d.ts +1 -0
  7. package/dist/types/components/Combobox/types.d.ts +19 -0
  8. package/dist/types/components/Command/Command.d.ts +67 -0
  9. package/dist/types/components/Command/constants.d.ts +11 -0
  10. package/dist/types/components/Command/index.d.ts +1 -0
  11. package/dist/types/components/Command/types.d.ts +8 -0
  12. package/dist/types/components/Description/types.d.ts +1 -0
  13. package/dist/types/components/Dialog/Dialog.d.ts +22 -0
  14. package/dist/types/components/Dialog/constants.d.ts +7 -0
  15. package/dist/types/components/Dialog/index.d.ts +1 -0
  16. package/dist/types/components/Dialog/types.d.ts +11 -0
  17. package/dist/types/components/Form/Checkbox/Checkbox.d.ts +6 -0
  18. package/dist/types/components/Form/Checkbox/constants.d.ts +4 -0
  19. package/dist/types/components/Form/Checkbox/index.d.ts +1 -0
  20. package/dist/types/components/Form/Checkbox/types.d.ts +4 -0
  21. package/dist/types/components/Form/Input/Input.d.ts +7 -0
  22. package/dist/types/components/Form/Input/constants.d.ts +6 -0
  23. package/dist/types/components/Form/Input/index.d.ts +1 -0
  24. package/dist/types/components/Form/Input/types.d.ts +4 -0
  25. package/dist/types/components/Form/Phone/Phone.d.ts +4 -0
  26. package/dist/types/components/Form/Phone/constants.d.ts +2 -0
  27. package/dist/types/components/Form/Phone/index.d.ts +1 -0
  28. package/dist/types/components/Form/Phone/types.d.ts +2 -0
  29. package/dist/types/components/Form/Radio/Radio.d.ts +6 -0
  30. package/dist/types/components/Form/Radio/constants.d.ts +4 -0
  31. package/dist/types/components/Form/Radio/index.d.ts +1 -0
  32. package/dist/types/components/Form/Radio/types.d.ts +4 -0
  33. package/dist/types/components/Form/Range/Range.d.ts +8 -0
  34. package/dist/types/components/Form/Range/constants.d.ts +6 -0
  35. package/dist/types/components/Form/Range/index.d.ts +1 -0
  36. package/dist/types/components/Form/Range/types.d.ts +4 -0
  37. package/dist/types/components/Form/Select/Select.d.ts +27 -0
  38. package/dist/types/components/Form/Select/constants.d.ts +17 -0
  39. package/dist/types/components/Form/Select/index.d.ts +1 -0
  40. package/dist/types/components/Form/Select/types.d.ts +7 -0
  41. package/dist/types/components/Form/Slider/Slider.d.ts +15 -0
  42. package/dist/types/components/Form/Slider/constants.d.ts +15 -0
  43. package/dist/types/components/Form/Slider/index.d.ts +1 -0
  44. package/dist/types/components/Form/Slider/types.d.ts +5 -0
  45. package/dist/types/components/Form/Switch/Switch.d.ts +6 -0
  46. package/dist/types/components/Form/Switch/constants.d.ts +4 -0
  47. package/dist/types/components/Form/Switch/index.d.ts +1 -0
  48. package/dist/types/components/Form/Switch/types.d.ts +4 -0
  49. package/dist/types/components/Form/TextField/TextField.d.ts +10 -0
  50. package/dist/types/components/Form/TextField/constants.d.ts +1 -0
  51. package/dist/types/components/Form/TextField/index.d.ts +1 -0
  52. package/dist/types/components/Form/TextField/types.d.ts +6 -0
  53. package/dist/types/components/Form/Textarea/Textarea.d.ts +8 -0
  54. package/dist/types/components/Form/Textarea/constants.d.ts +6 -0
  55. package/dist/types/components/Form/Textarea/index.d.ts +1 -0
  56. package/dist/types/components/Form/Textarea/types.d.ts +4 -0
  57. package/dist/types/components/Form/components/FormControl/FormControl.d.ts +2 -0
  58. package/dist/types/components/Form/components/FormControl/constants.d.ts +1 -0
  59. package/dist/types/components/Form/components/FormControl/index.d.ts +1 -0
  60. package/dist/types/components/Form/components/FormControl/types.d.ts +9 -0
  61. package/dist/types/components/Form/components/Label/Label.d.ts +7 -0
  62. package/dist/types/components/Form/components/Label/constants.d.ts +1 -0
  63. package/dist/types/components/Form/components/Label/index.d.ts +1 -0
  64. package/dist/types/components/Form/components/Label/types.d.ts +6 -0
  65. package/dist/types/components/Form/index.d.ts +11 -0
  66. package/dist/types/components/Loading/types.d.ts +1 -0
  67. package/dist/types/components/Popover/Popover.d.ts +9 -0
  68. package/dist/types/components/Popover/constants.d.ts +1 -0
  69. package/dist/types/components/Popover/index.d.ts +1 -0
  70. package/dist/types/components/Popover/types.d.ts +6 -0
  71. package/dist/types/components/Progress/Progress.d.ts +3 -3
  72. package/dist/types/components/Progress/types.d.ts +1 -0
  73. package/dist/types/components/Separator/types.d.ts +1 -0
  74. package/dist/types/components/Skeleton/types.d.ts +1 -0
  75. package/dist/types/components/Text/Text.d.ts +2 -2
  76. package/dist/types/components/Text/types.d.ts +6 -2
  77. package/dist/types/components/Tooltip/Tooltip.d.ts +3 -3
  78. package/dist/types/components/Tooltip/types.d.ts +1 -0
  79. package/dist/types/index.d.ts +6 -0
  80. package/dist/types/libs/cva.d.ts +6 -1
  81. package/package.json +21 -13
  82. package/src/components/Combobox/Combobox.tsx +82 -0
  83. package/src/components/Combobox/index.ts +1 -0
  84. package/src/components/Combobox/types.ts +21 -0
  85. package/src/components/Command/Command.tsx +142 -0
  86. package/src/components/Command/constants.ts +39 -0
  87. package/src/components/Command/index.ts +1 -0
  88. package/src/components/Command/types.ts +16 -0
  89. package/src/components/Dialog/Dialog.tsx +105 -0
  90. package/src/components/Dialog/constants.ts +27 -0
  91. package/src/components/Dialog/index.ts +1 -0
  92. package/src/components/Dialog/types.ts +40 -0
  93. package/src/components/Form/Checkbox/Checkbox.tsx +18 -0
  94. package/src/components/Form/Checkbox/constants.ts +21 -0
  95. package/src/components/Form/Checkbox/index.ts +1 -0
  96. package/src/components/Form/Checkbox/types.ts +8 -0
  97. package/src/components/Form/Input/Input.tsx +18 -0
  98. package/src/components/Form/Input/constants.ts +37 -0
  99. package/src/components/Form/Input/index.ts +1 -0
  100. package/src/components/Form/Input/types.ts +8 -0
  101. package/src/components/Form/Phone/Phone.tsx +126 -0
  102. package/src/components/Form/Phone/constants.ts +7 -0
  103. package/src/components/Form/Phone/index.ts +1 -0
  104. package/src/components/Form/Phone/types.ts +3 -0
  105. package/src/components/Form/Radio/Radio.tsx +18 -0
  106. package/src/components/Form/Radio/constants.ts +21 -0
  107. package/src/components/Form/Radio/index.ts +1 -0
  108. package/src/components/Form/Radio/types.ts +8 -0
  109. package/src/components/Form/Range/Range.tsx +22 -0
  110. package/src/components/Form/Range/constants.ts +31 -0
  111. package/src/components/Form/Range/index.ts +1 -0
  112. package/src/components/Form/Range/types.ts +8 -0
  113. package/src/components/Form/Select/Select.tsx +151 -0
  114. package/src/components/Form/Select/constants.ts +80 -0
  115. package/src/components/Form/Select/index.ts +1 -0
  116. package/src/components/Form/Select/types.ts +18 -0
  117. package/src/components/Form/Slider/Slider.tsx +43 -0
  118. package/src/components/Form/Slider/constants.ts +87 -0
  119. package/src/components/Form/Slider/index.ts +1 -0
  120. package/src/components/Form/Slider/types.ts +16 -0
  121. package/src/components/Form/Switch/Switch.tsx +19 -0
  122. package/src/components/Form/Switch/constants.ts +21 -0
  123. package/src/components/Form/Switch/index.ts +1 -0
  124. package/src/components/Form/Switch/types.ts +8 -0
  125. package/src/components/Form/TextField/TextField.tsx +37 -0
  126. package/src/components/Form/TextField/constants.ts +5 -0
  127. package/src/components/Form/TextField/index.ts +1 -0
  128. package/src/components/Form/TextField/types.ts +7 -0
  129. package/src/components/Form/Textarea/Textarea.tsx +22 -0
  130. package/src/components/Form/Textarea/constants.ts +37 -0
  131. package/src/components/Form/Textarea/index.ts +1 -0
  132. package/src/components/Form/Textarea/types.ts +8 -0
  133. package/src/components/Form/components/FormControl/FormControl.tsx +21 -0
  134. package/src/components/Form/components/FormControl/constants.ts +3 -0
  135. package/src/components/Form/components/FormControl/index.ts +1 -0
  136. package/src/components/Form/components/FormControl/types.ts +13 -0
  137. package/src/components/Form/components/Label/Label.tsx +22 -0
  138. package/src/components/Form/components/Label/constants.ts +3 -0
  139. package/src/components/Form/components/Label/index.ts +1 -0
  140. package/src/components/Form/components/Label/types.ts +10 -0
  141. package/src/components/Form/index.ts +11 -0
  142. package/src/components/Popover/Popover.tsx +30 -0
  143. package/src/components/Popover/constants.ts +5 -0
  144. package/src/components/Popover/index.ts +1 -0
  145. package/src/components/Popover/types.ts +12 -0
  146. package/src/components/Text/Text.tsx +3 -3
  147. package/src/components/Text/types.ts +8 -5
  148. package/src/index.ts +7 -0
  149. package/src/libs/cva.ts +10 -1
@@ -0,0 +1,40 @@
1
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
2
+ import { type VariantProps } from "../../libs";
3
+ import {
4
+ getDialogContentClasses,
5
+ getDialogDescriptionClasses,
6
+ getDialogFooterClasses,
7
+ getDialogHeaderClasses,
8
+ getDialogOverlayClasses,
9
+ getDialogTitleClasses,
10
+ } from "./constants";
11
+
12
+ export type DialogProps = React.ComponentPropsWithoutRef<
13
+ typeof DialogPrimitive.Root
14
+ >;
15
+
16
+ export type DialogOverlayProps = React.ComponentPropsWithoutRef<
17
+ typeof DialogPrimitive.Overlay
18
+ > &
19
+ VariantProps<typeof getDialogOverlayClasses>;
20
+
21
+ export type DialogContentProps = React.ComponentPropsWithoutRef<
22
+ typeof DialogPrimitive.Content
23
+ > &
24
+ VariantProps<typeof getDialogContentClasses>;
25
+
26
+ export type DialogHeaderProps = React.HTMLAttributes<HTMLDivElement> &
27
+ VariantProps<typeof getDialogHeaderClasses>;
28
+
29
+ export type DialogFooterProps = React.HTMLAttributes<HTMLDivElement> &
30
+ VariantProps<typeof getDialogFooterClasses>;
31
+
32
+ export type DialogTitleProps = React.ComponentPropsWithoutRef<
33
+ typeof DialogPrimitive.Title
34
+ > &
35
+ VariantProps<typeof getDialogTitleClasses>;
36
+
37
+ export type DialogDescriptionProps = React.ComponentPropsWithoutRef<
38
+ typeof DialogPrimitive.Description
39
+ > &
40
+ VariantProps<typeof getDialogDescriptionClasses>;
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ import { type CheckboxProps } from "./types";
3
+ import { getCheckboxClasses } from "./constants";
4
+ import { cn } from "../../../utilities";
5
+
6
+ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
7
+ ({ className, size, variant, ...props }, ref) => (
8
+ <input
9
+ ref={ref}
10
+ type="checkbox"
11
+ className={cn(getCheckboxClasses({ size, variant }), className)}
12
+ {...props}
13
+ />
14
+ )
15
+ );
16
+ Checkbox.displayName = "Checkbox";
17
+
18
+ export { Checkbox };
@@ -0,0 +1,21 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getCheckboxClasses = cva("checkbox", {
4
+ variants: {
5
+ variant: {
6
+ primary: "checkbox-primary",
7
+ secondary: "checkbox-secondary",
8
+ accent: "checkbox-accent",
9
+ success: "checkbox-success",
10
+ warning: "checkbox-warning",
11
+ info: "checkbox-info",
12
+ error: "checkbox-error",
13
+ },
14
+ size: {
15
+ xs: "checkbox-xs",
16
+ sm: "checkbox-sm",
17
+ md: "checkbox-md",
18
+ lg: "checkbox-lg",
19
+ },
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export { Checkbox } from "./Checkbox";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getCheckboxClasses } from "./constants";
3
+
4
+ export type CheckboxProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref" | "type"
7
+ > &
8
+ VariantProps<typeof getCheckboxClasses>;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { type InputProps } from "./types";
3
+ import { cn } from "../../../utilities";
4
+ import { getInputClasses } from "./constants";
5
+
6
+ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
7
+ ({ size, variant, wide, outline, className, ...props }: InputProps, ref) => (
8
+ <input
9
+ ref={ref}
10
+ className={cn(
11
+ getInputClasses({ size, wide, variant, outline }),
12
+ className
13
+ )}
14
+ {...props}
15
+ />
16
+ )
17
+ );
18
+ Input.displayName = "Input";
@@ -0,0 +1,37 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getInputClasses = cva(
4
+ "input rounded-md transition-all duration-100",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ accent: "input-accent",
9
+ error: "input-error",
10
+ ghost: "input-ghost",
11
+ info: "input-info",
12
+ primary: "input-primary",
13
+ secondary: "input-secondary",
14
+ success: "input-success",
15
+ warning: "input-warning",
16
+ },
17
+ outline: {
18
+ true: "input-bordered",
19
+ },
20
+ wide: {
21
+ true: "w-full",
22
+ },
23
+ size: {
24
+ xs: "input-xs",
25
+ sm: "input-sm",
26
+ md: "input-md",
27
+ lg: "input-lg",
28
+ },
29
+ },
30
+ compoundVariants: [
31
+ {
32
+ size: undefined,
33
+ className: "min-h-fit h-10",
34
+ },
35
+ ],
36
+ }
37
+ );
@@ -0,0 +1 @@
1
+ export { Input } from "./Input";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getInputClasses } from "./constants";
3
+
4
+ export type InputProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref"
7
+ > &
8
+ VariantProps<typeof getInputClasses>;
@@ -0,0 +1,126 @@
1
+ "use client";
2
+
3
+ import React, { MutableRefObject } from "react";
4
+ import {
5
+ defaultCountries,
6
+ usePhoneInput,
7
+ FlagImage,
8
+ } from "react-international-phone";
9
+ import { type PhoneProps } from "./types";
10
+ import { Popover } from "../../Popover";
11
+ import { Command } from "../../Command";
12
+ import { cn } from "../../../utilities";
13
+ import { Button } from "../../Button";
14
+ import { Input } from "../Input";
15
+ import { getPhoneButtonClasses, getPhoneInputClasses } from "./constants";
16
+
17
+ const Phone = React.forwardRef<HTMLInputElement, PhoneProps>(
18
+ (
19
+ {
20
+ disabled,
21
+ defaultValue,
22
+ className,
23
+ placeholder,
24
+ onChange,
25
+ variant,
26
+ outline,
27
+ wide,
28
+ size,
29
+ ...props
30
+ },
31
+ ref
32
+ ) => {
33
+ const [open, setOpen] = React.useState(false);
34
+ const {
35
+ inputValue,
36
+ handlePhoneValueChange,
37
+ inputRef,
38
+ country,
39
+ setCountry,
40
+ } = usePhoneInput({
41
+ value: String(defaultValue) ?? "+231",
42
+ defaultCountry: "lr",
43
+ forceDialCode: true,
44
+ inputRef: ref as MutableRefObject<HTMLInputElement | null>,
45
+ });
46
+
47
+ const options = defaultCountries.map((country) => ({
48
+ label: country[0],
49
+ value: country[1],
50
+ }));
51
+
52
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
53
+ handlePhoneValueChange(e);
54
+ onChange?.(e);
55
+ };
56
+
57
+ return (
58
+ <div className="join">
59
+ <Popover open={open} onOpenChange={setOpen}>
60
+ <Popover.Trigger asChild>
61
+ <Button
62
+ role="combobox"
63
+ aria-expanded={open}
64
+ size={size}
65
+ variant={variant}
66
+ outline={outline}
67
+ className={cn(getPhoneButtonClasses())}
68
+ disabled={disabled}
69
+ >
70
+ <FlagImage
71
+ iso2={country.iso2}
72
+ size={["xs", "sm"].includes(size!) ? "20px" : "30px"}
73
+ />
74
+ </Button>
75
+ </Popover.Trigger>
76
+ <Popover.Content className="w-[200px] p-0">
77
+ <Command>
78
+ <Command.Input placeholder="Search country..." />
79
+ <Command.Empty>No country found.</Command.Empty>
80
+ <Command.List>
81
+ <Command.Group>
82
+ {options.map((option) => (
83
+ <Command.Item
84
+ key={option.value}
85
+ value={option.value}
86
+ keywords={[option.label, option.value]}
87
+ onSelect={(currentValue) => {
88
+ setCountry(currentValue);
89
+ setOpen(false);
90
+ }}
91
+ className={cn({
92
+ "bg-base-300": country.iso2 === option.value,
93
+ })}
94
+ >
95
+ <FlagImage iso2={option.value} size="20px" />
96
+ <span className="truncate ml-2">{option.label}</span>
97
+ </Command.Item>
98
+ ))}
99
+ </Command.Group>
100
+ </Command.List>
101
+ </Command>
102
+ </Popover.Content>
103
+ </Popover>
104
+ <Input
105
+ type="text"
106
+ ref={inputRef}
107
+ value={inputValue}
108
+ pattern="^\+\d{1,4}\s\d{6,}$"
109
+ inputMode="numeric"
110
+ placeholder={placeholder ?? " "}
111
+ onChange={handleInputChange}
112
+ size={size}
113
+ wide={wide}
114
+ variant={variant}
115
+ outline={outline}
116
+ disabled={disabled}
117
+ className={cn(getPhoneInputClasses(), className)}
118
+ {...props}
119
+ />
120
+ </div>
121
+ );
122
+ }
123
+ );
124
+ Phone.displayName = "Phone";
125
+
126
+ export { Phone };
@@ -0,0 +1,7 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getPhoneButtonClasses = cva("join-item justify-between px-2");
4
+
5
+ export const getPhoneInputClasses = cva(
6
+ "input join-item input-bordered w-full !rounded-l-none !pl-2 transition-all duration-100"
7
+ );
@@ -0,0 +1 @@
1
+ export { Phone } from "./Phone";
@@ -0,0 +1,3 @@
1
+ import { type InputProps } from "../Input/types";
2
+
3
+ export type PhoneProps = Omit<InputProps, "type" | "label" | "inputMode">;
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ import { type RadioProps } from "./types";
3
+ import { getRadioClasses } from "./constants";
4
+ import { cn } from "../../../utilities";
5
+
6
+ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
7
+ ({ className, size, variant, ...props }, ref) => (
8
+ <input
9
+ ref={ref}
10
+ type="radio"
11
+ className={cn(getRadioClasses({ size, variant }), className)}
12
+ {...props}
13
+ />
14
+ )
15
+ );
16
+ Radio.displayName = "Radio";
17
+
18
+ export { Radio };
@@ -0,0 +1,21 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getRadioClasses = cva("radio", {
4
+ variants: {
5
+ variant: {
6
+ primary: "radio-primary",
7
+ secondary: "radio-secondary",
8
+ accent: "radio-accent",
9
+ success: "radio-success",
10
+ warning: "radio-warning",
11
+ info: "radio-info",
12
+ error: "radio-error",
13
+ },
14
+ size: {
15
+ xs: "radio-xs",
16
+ sm: "radio-sm",
17
+ md: "radio-md",
18
+ lg: "radio-lg",
19
+ },
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export { Radio } from "./Radio";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getRadioClasses } from "./constants";
3
+
4
+ export type RadioProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref" | "type"
7
+ > &
8
+ VariantProps<typeof getRadioClasses>;
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ import { type RangeProps } from "./types";
3
+ import { getRangeClasses } from "./constants";
4
+ import { cn } from "../../../utilities";
5
+
6
+ const Range = React.forwardRef<HTMLInputElement, RangeProps>(
7
+ ({ className, size, variant, wide, disabled, ...props }, ref) => (
8
+ <input
9
+ ref={ref}
10
+ type="range"
11
+ disabled={disabled}
12
+ className={cn(
13
+ getRangeClasses({ size, variant, wide, disabled }),
14
+ className
15
+ )}
16
+ {...props}
17
+ />
18
+ )
19
+ );
20
+ Range.displayName = "Range";
21
+
22
+ export { Range };
@@ -0,0 +1,31 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getRangeClasses = cva("range", {
4
+ variants: {
5
+ variant: {
6
+ primary: "range-primary",
7
+ secondary: "range-secondary",
8
+ accent: "range-accent",
9
+ success: "range-success",
10
+ warning: "range-warning",
11
+ info: "range-info",
12
+ error: "range-error",
13
+ neutral: "range-neutral",
14
+ },
15
+ disabled: {
16
+ true: "cursor-not-allowed opacity-80",
17
+ },
18
+ wide: {
19
+ true: "w-full",
20
+ },
21
+ size: {
22
+ xs: "range-xs",
23
+ sm: "range-sm",
24
+ md: "range-md",
25
+ lg: "range-lg",
26
+ },
27
+ },
28
+ defaultVariants: {
29
+ variant: "neutral",
30
+ },
31
+ });
@@ -0,0 +1 @@
1
+ export { Range } from "./Range";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getRangeClasses } from "./constants";
3
+
4
+ export type RangeProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref" | "type"
7
+ > &
8
+ VariantProps<typeof getRangeClasses>;
@@ -0,0 +1,151 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ CheckIcon,
6
+ ChevronDownIcon,
7
+ ChevronUpIcon,
8
+ } from "@radix-ui/react-icons";
9
+ import * as SelectPrimitive from "@radix-ui/react-select";
10
+ import type {
11
+ SelectContentProps,
12
+ SelectItemProps,
13
+ SelectTriggerProps,
14
+ } from "./types";
15
+ import { cn } from "../../../utilities";
16
+ import {
17
+ getSelectContentClasses,
18
+ getSelectItemClasses,
19
+ getSelectLabelClasses,
20
+ getSelectSeparatorClasses,
21
+ getSelectTriggerClasses,
22
+ getSelectViewportClasses,
23
+ } from "./constants";
24
+
25
+ const Select = (
26
+ props: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Root>
27
+ ) => <SelectPrimitive.Root {...props} />;
28
+
29
+ const SelectTrigger = React.forwardRef<
30
+ React.ElementRef<typeof SelectPrimitive.Trigger>,
31
+ SelectTriggerProps
32
+ >(({ className, children, size, wide, variant, outline, ...props }, ref) => (
33
+ <SelectPrimitive.Trigger
34
+ ref={ref}
35
+ className={cn(
36
+ getSelectTriggerClasses({ size, wide, variant, outline }),
37
+ className
38
+ )}
39
+ {...props}
40
+ >
41
+ {children}
42
+ </SelectPrimitive.Trigger>
43
+ ));
44
+ SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
45
+
46
+ const SelectScrollUpButton = React.forwardRef<
47
+ React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
48
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
49
+ >((props, ref) => (
50
+ <SelectPrimitive.ScrollUpButton
51
+ ref={ref}
52
+ className={cn("flex cursor-default items-center justify-center py-1")}
53
+ {...props}
54
+ >
55
+ <ChevronUpIcon />
56
+ </SelectPrimitive.ScrollUpButton>
57
+ ));
58
+ SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
59
+
60
+ const SelectScrollDownButton = React.forwardRef<
61
+ React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
62
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
63
+ >((props, ref) => (
64
+ <SelectPrimitive.ScrollDownButton
65
+ ref={ref}
66
+ className={cn("flex cursor-default items-center justify-center py-1")}
67
+ {...props}
68
+ >
69
+ <ChevronDownIcon />
70
+ </SelectPrimitive.ScrollDownButton>
71
+ ));
72
+ SelectScrollDownButton.displayName =
73
+ SelectPrimitive.ScrollDownButton.displayName;
74
+
75
+ const SelectContent = React.forwardRef<
76
+ React.ElementRef<typeof SelectPrimitive.Content>,
77
+ SelectContentProps
78
+ >(({ className, children, position = "popper", ...props }, ref) => (
79
+ <SelectPrimitive.Portal>
80
+ <SelectPrimitive.Content
81
+ ref={ref}
82
+ className={cn(getSelectContentClasses({ position }), className)}
83
+ position={position}
84
+ {...props}
85
+ >
86
+ <SelectScrollUpButton />
87
+ <SelectPrimitive.Viewport
88
+ className={cn(getSelectViewportClasses({ position }))}
89
+ >
90
+ {children}
91
+ </SelectPrimitive.Viewport>
92
+ <SelectScrollDownButton />
93
+ </SelectPrimitive.Content>
94
+ </SelectPrimitive.Portal>
95
+ ));
96
+ SelectContent.displayName = SelectPrimitive.Content.displayName;
97
+
98
+ const SelectLabel = React.forwardRef<
99
+ React.ElementRef<typeof SelectPrimitive.Label>,
100
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
101
+ >((props, ref) => (
102
+ <SelectPrimitive.Label
103
+ ref={ref}
104
+ className={cn(getSelectLabelClasses())}
105
+ {...props}
106
+ />
107
+ ));
108
+ SelectLabel.displayName = SelectPrimitive.Label.displayName;
109
+
110
+ const SelectItem = React.forwardRef<
111
+ React.ElementRef<typeof SelectPrimitive.Item>,
112
+ SelectItemProps
113
+ >(({ className, children, variant, ...props }, ref) => (
114
+ <SelectPrimitive.Item
115
+ ref={ref}
116
+ className={cn(getSelectItemClasses({ variant }), className)}
117
+ {...props}
118
+ >
119
+ <span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
120
+ <SelectPrimitive.ItemIndicator>
121
+ <CheckIcon className="h-4 w-4" />
122
+ </SelectPrimitive.ItemIndicator>
123
+ </span>
124
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
125
+ </SelectPrimitive.Item>
126
+ ));
127
+ SelectItem.displayName = SelectPrimitive.Item.displayName;
128
+
129
+ const SelectSeparator = React.forwardRef<
130
+ React.ElementRef<typeof SelectPrimitive.Separator>,
131
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
132
+ >((props, ref) => (
133
+ <SelectPrimitive.Separator
134
+ ref={ref}
135
+ className={cn(getSelectSeparatorClasses())}
136
+ {...props}
137
+ />
138
+ ));
139
+ SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
140
+
141
+ Select.Group = SelectPrimitive.Group;
142
+ Select.Value = SelectPrimitive.Value;
143
+ Select.Trigger = SelectTrigger;
144
+ Select.Content = SelectContent;
145
+ Select.Label = SelectLabel;
146
+ Select.Item = SelectItem;
147
+ Select.Separator = SelectSeparator;
148
+ Select.ScrollUpButton = SelectScrollUpButton;
149
+ Select.ScrollDownButton = SelectScrollDownButton;
150
+
151
+ export { Select };
@@ -0,0 +1,80 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getSelectTriggerClasses = cva(
4
+ "select flex items-center justify-between rounded-md text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ primary: "select-primary",
9
+ secondary: "select-secondary",
10
+ accent: "select-accent",
11
+ success: "select-success",
12
+ warning: "select-warning",
13
+ info: "select-info",
14
+ error: "select-error",
15
+ },
16
+ outline: {
17
+ true: "select-bordered border border-input",
18
+ },
19
+ wide: {
20
+ true: "w-full",
21
+ },
22
+ size: {
23
+ xs: "select-xs",
24
+ sm: "select-sm",
25
+ md: "select-md",
26
+ lg: "select-lg",
27
+ },
28
+ },
29
+ compoundVariants: [
30
+ {
31
+ size: undefined,
32
+ className: "min-h-fit h-10",
33
+ },
34
+ ],
35
+ }
36
+ );
37
+
38
+ export const getSelectItemClasses = cva(
39
+ "relative flex w-full cursor-pointer select-none items-center focus:bg-neutral focus:text-neutral-content rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
40
+ {
41
+ variants: {
42
+ variant: {
43
+ primary: "focus:bg-primary focus:text-primary-content",
44
+ secondary: "focus:bg-secondary focus:text-secondary-content",
45
+ accent: "focus:bg-accent focus:text-accent-content",
46
+ success: "focus:bg-success focus:text-success-content",
47
+ warning: "focus:bg-warning focus:text-warning-content",
48
+ info: "focus:bg-info focus:text-info-content",
49
+ error: "focus:bg-error focus:text-error-content",
50
+ },
51
+ },
52
+ }
53
+ );
54
+
55
+ export const getSelectLabelClasses = cva("px-2 py-1.5 text-sm font-semibold");
56
+
57
+ export const getSelectSeparatorClasses = cva("-mx-1 my-1 h-px bg-muted");
58
+
59
+ export const getSelectContentClasses = cva(
60
+ "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-base-100 shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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",
61
+ {
62
+ variants: {
63
+ position: {
64
+ popper:
65
+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
66
+ "item-aligned": "",
67
+ },
68
+ },
69
+ }
70
+ );
71
+
72
+ export const getSelectViewportClasses = cva("p-1", {
73
+ variants: {
74
+ position: {
75
+ popper:
76
+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]",
77
+ "item-aligned": "",
78
+ },
79
+ },
80
+ });
@@ -0,0 +1 @@
1
+ export { Select } from "./Select";