@gentleduck/registry-ui 0.3.0 → 0.3.2

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 (35) hide show
  1. package/.turbo/turbo-test.log +19 -19
  2. package/CHANGELOG.md +14 -0
  3. package/LICENSE +21 -0
  4. package/SECURITY.md +19 -0
  5. package/bunfig.toml +2 -0
  6. package/package.json +12 -4
  7. package/src/calendar/calendar-day.tsx +131 -0
  8. package/src/calendar/calendar-header.tsx +291 -0
  9. package/src/calendar/calendar.tsx +195 -182
  10. package/src/calendar/calendar.types.ts +135 -0
  11. package/src/calendar/calendar.utils.ts +23 -0
  12. package/src/calendar/index.ts +2 -1
  13. package/src/sonner/sonner.chunks.tsx +0 -1
  14. package/tsconfig.json +1 -1
  15. package/src/_old/_table/index.ts +0 -14
  16. package/src/_old/_table/table-advanced.constants.tsx +0 -24
  17. package/src/_old/_table/table-advanced.tsx +0 -311
  18. package/src/_old/_table/table-advanced.types.ts +0 -272
  19. package/src/_old/_table/table.constants.ts +0 -2
  20. package/src/_old/_table/table.hook.tsx +0 -115
  21. package/src/_old/_table/table.lib.ts +0 -85
  22. package/src/_old/_table/table.tsx +0 -916
  23. package/src/_old/_table/table.types.ts +0 -118
  24. package/src/_old/_table/todo.md +0 -11
  25. package/src/_old/_upload/index.ts +0 -22
  26. package/src/_old/_upload/todo.md +0 -38
  27. package/src/_old/_upload/upload-advanced-chunks.tsx +0 -1624
  28. package/src/_old/_upload/upload-advanced.tsx +0 -507
  29. package/src/_old/_upload/upload-sonner.tsx +0 -58
  30. package/src/_old/_upload/upload.assets.tsx +0 -239
  31. package/src/_old/_upload/upload.constants.tsx +0 -75
  32. package/src/_old/_upload/upload.dto.ts +0 -19
  33. package/src/_old/_upload/upload.lib.tsx +0 -630
  34. package/src/_old/_upload/upload.tsx +0 -491
  35. package/src/_old/_upload/upload.types.ts +0 -436
@@ -1,311 +0,0 @@
1
- import { cn } from '@gentleduck/libs/cn'
2
- import { ArrowDownIcon, ArrowUpDown, ArrowUpIcon } from 'lucide-react'
3
- import React from 'react'
4
- import { Button } from '../button'
5
- import { Checkbox } from '../checkbox'
6
- import {
7
- DropdownMenu,
8
- DropdownMenuContent,
9
- DropdownMenuGroup,
10
- DropdownMenuItem,
11
- DropdownMenuSeparator,
12
- DropdownMenuTrigger,
13
- } from '../dropdown-menu'
14
- import { Input } from '../input'
15
- import { ScrollArea } from '../scroll-area/'
16
- import { TableHead, TableHeader, TableRow } from '../table'
17
- import { Table, TableBody } from './table'
18
- import { dropdownMenuOptions } from './table-advanced.constants'
19
- import {
20
- DuckTableBodyProps,
21
- DuckTableContextType,
22
- DuckTableHeadCheckboxProps,
23
- DuckTableHeaderProps,
24
- DuckTableHeadSelectableProps,
25
- DuckTableProps,
26
- DuckTableProviderProps,
27
- DuckTableRowCheckboxProps,
28
- GetColumnLabel,
29
- TableColumnType,
30
- TableContentDataType,
31
- TableSearchStateType,
32
- } from './table-advanced.types'
33
-
34
- export const DuckTableContext = React.createContext<DuckTableContextType<any> | null>(null)
35
-
36
- export function useDuckTable<TColumnName extends readonly TableColumnType[]>() {
37
- const context = React.useContext<DuckTableContextType<GetColumnLabel<TColumnName>>>(
38
- DuckTableContext as unknown as React.Context<DuckTableContextType<GetColumnLabel<TColumnName>>>,
39
- )
40
- if (!context) {
41
- throw new Error('useTableProvider must be used within an TableProvider')
42
- }
43
- return context
44
- }
45
-
46
- export function DuckTableProvider<TColumnName extends string[]>({
47
- table_rows,
48
- table_columns,
49
- children,
50
- className,
51
- ...props
52
- }: DuckTableProviderProps<TColumnName>) {
53
- const [search, setSearch] = React.useState<TableSearchStateType>({
54
- query: '',
55
- queryBy: [],
56
- })
57
-
58
- const [tableColumns, setTableColumns] = React.useState<Map<string, TableColumnType>>(
59
- new Map(table_columns.map((column) => [column.label, column])),
60
- )
61
-
62
- const [selectedRows, setSelectedRows] = React.useState<Set<TableContentDataType<TColumnName>>>(new Set())
63
-
64
- const DuckTable = DuckTableContext //<TColumnName>()
65
-
66
- return (
67
- <DuckTable.Provider
68
- value={{
69
- search,
70
- selectedRows,
71
- setSearch,
72
- setSelectedRows,
73
- setTableColumns,
74
- tableColumns,
75
- tableRows: table_rows,
76
- }}>
77
- <div className={cn(`w-full- flex flex-col gap-4 w-[800px] h-[500px]`, className)} {...props}>
78
- {children}
79
- </div>
80
- </DuckTable.Provider>
81
- )
82
- }
83
- DuckTableProvider.displayName = 'DuckTableProvider'
84
-
85
- export function DuckTable({ wrapper, className, children, ...props }: DuckTableProps) {
86
- const { className: wrapperClassName, ...wrapperProps } = wrapper! ?? {}
87
-
88
- return (
89
- <ScrollArea
90
- className={cn('border border-border rounded-lg !overflow-visible relative', wrapperClassName)}
91
- {...wrapperProps}>
92
- <Table {...props}>{children}</Table>
93
- </ScrollArea>
94
- )
95
- }
96
- DuckTable.displayName = 'DuckTable'
97
-
98
- // ------------------------------------------------------------------------------------------------
99
-
100
- export function DuckTableHeader({}: DuckTableHeaderProps) {
101
- const { tableColumns } = useDuckTable()
102
- return (
103
- <>
104
- <TableHeader>
105
- <TableRow>
106
- {Array.from(tableColumns.values())?.map((column, idx) => {
107
- const { children, className, sortable, label, showLabel, ...props } = column
108
-
109
- const Component = () =>
110
- sortable ? (
111
- <DuckTableHeadSelectable column={column} label={(label as string) ?? children} showLabel={showLabel} />
112
- ) : (
113
- <span className="capitalize">{(label as string) ?? children}</span>
114
- )
115
-
116
- return (
117
- !column['aria-hidden'] && (
118
- <React.Fragment key={idx}>
119
- <TableHead
120
- className={cn('py-2', idx === 0 && 'justify-start ', sortable && 'px-2', className)}
121
- {...props}>
122
- {idx === 0 ? (
123
- <div className="flex items-center gap-4">
124
- <DuckTableHeadCheckbox className={cn(sortable && 'justify-end')} type="header" />
125
- {/*NOTE: Rendering Sorting else rendering label*/}
126
- <Component />
127
- </div>
128
- ) : (
129
- <Component />
130
- )}
131
- </TableHead>
132
- </React.Fragment>
133
- )
134
- )
135
- })}
136
- </TableRow>
137
- </TableHeader>
138
- </>
139
- )
140
- }
141
- DuckTableHeader.displayName = 'TableCustomViewHeader'
142
-
143
- export function DuckTableHeadCheckbox({ className, ...props }: DuckTableHeadCheckboxProps) {
144
- const { selectedRows, setSelectedRows, tableRows } = useDuckTable()
145
-
146
- return (
147
- <div className={cn('flex items-center w-fit data-[state=open]:bg-accent text-xs capitalize', className)} {...props}>
148
- <Checkbox
149
- checked={
150
- selectedRows.size === tableRows.length
151
- ? true
152
- : selectedRows.size < tableRows.length && selectedRows.size
153
- ? 'indeterminate'
154
- : false
155
- }
156
- className="border-border"
157
- onClick={() => {
158
- setSelectedRows(() => {
159
- if (selectedRows.size === tableRows.length) {
160
- return new Set()
161
- }
162
- return new Set(tableRows.map((item) => item))
163
- })
164
- }}
165
- />
166
- </div>
167
- )
168
- }
169
-
170
- export function DuckTableHeadSelectable<TSort extends boolean = true>({
171
- column,
172
- label,
173
- showLabel,
174
- children,
175
- }: DuckTableHeadSelectableProps<TSort>) {
176
- const { setTableColumns } = useDuckTable()
177
-
178
- return (
179
- <div className={cn('flex items-center space-x-2')}>
180
- {(dropdownMenuOptions?.length ?? 0) > 0 && (
181
- <DropdownMenu>
182
- <DropdownMenuTrigger asChild>
183
- <Button
184
- aria-controls="dropdown-menu"
185
- aria-label="table-column-options"
186
- aria-sort={column['aria-sort']}
187
- className="data-[state=open]:bg-accent [&>div]:justify-between w-full [&>div]:w-full capitalize"
188
- label={
189
- showLabel
190
- ? {
191
- children: label.toString() + ' options',
192
- className: 'capitalize',
193
- showLabel: true,
194
- side: 'top',
195
- }
196
- : undefined
197
- }
198
- name="dropdown-menu-trigger"
199
- secondIcon={
200
- column['aria-sort'] === 'ascending' ? (
201
- <ArrowDownIcon className="text-muted-foreground" />
202
- ) : column['aria-sort'] === 'descending' ? (
203
- <ArrowUpIcon className="text-muted-foreground" />
204
- ) : (
205
- <ArrowUpDown className="text-muted-foreground" />
206
- )
207
- }
208
- size="sm"
209
- variant="ghost">
210
- {(label as string) ?? children}
211
- </Button>
212
- </DropdownMenuTrigger>
213
- <DropdownMenuContent className="w-48">
214
- <DropdownMenuGroup>
215
- {dropdownMenuOptions.map((item, idx) => {
216
- return (
217
- <>
218
- {idx === dropdownMenuOptions.length - 1 && <DropdownMenuSeparator />}
219
- <DropdownMenuItem
220
- className="p-0"
221
- key={idx}
222
- onClick={() => {
223
- setTableColumns((prev) => {
224
- const newSet = new Map(prev)
225
-
226
- if (item.children === ('hide' as 'other')) {
227
- newSet.set(label, {
228
- ...column,
229
- 'aria-hidden': true,
230
- hidden: true,
231
- })
232
- } else {
233
- if (newSet.get(label)?.label === item.children) {
234
- newSet.set(label, {
235
- ...column,
236
- 'aria-sort': 'none',
237
- })
238
- } else {
239
- newSet.set(label, {
240
- ...column,
241
- 'aria-sort': item.children,
242
- })
243
- }
244
- }
245
-
246
- return newSet
247
- })
248
- }}>
249
- <Button {...item} className={cn('w-full justify-start capitalize', item.className)}>
250
- {item.children}
251
- </Button>
252
- </DropdownMenuItem>
253
- </>
254
- )
255
- })}
256
- </DropdownMenuGroup>
257
- </DropdownMenuContent>
258
- </DropdownMenu>
259
- )}
260
- </div>
261
- )
262
- }
263
-
264
- export function DuckTableBody({ children }: DuckTableBodyProps) {
265
- return <TableBody>{children}</TableBody>
266
- }
267
-
268
- export function DuckTableRowCheckbox<TColumnName extends readonly TableColumnType[]>({
269
- className,
270
- tableRow,
271
- ...props
272
- }: DuckTableRowCheckboxProps<TColumnName>) {
273
- const { selectedRows, setSelectedRows } = useDuckTable()
274
-
275
- return (
276
- <div className={cn('flex items-center w-fit data-[state=open]:bg-accent text-xs capitalize', className)} {...props}>
277
- <Checkbox
278
- checked={selectedRows.has(tableRow) ? true : false}
279
- className="border-border"
280
- onClick={() => {
281
- setSelectedRows(() => {
282
- if (selectedRows.has(tableRow)) {
283
- return new Set(Array.from(selectedRows.values()).filter((item) => item !== tableRow))
284
- }
285
- return new Set([...selectedRows, tableRow])
286
- })
287
- }}
288
- />
289
- </div>
290
- )
291
- }
292
-
293
- export interface DuckTableTopBarProps extends React.HTMLProps<HTMLDivElement> {}
294
-
295
- export function DuckTableTopBar({ className, children, ...props }: DuckTableTopBarProps) {
296
- return (
297
- <div className={cn('', className)} {...props}>
298
- {children}
299
- </div>
300
- )
301
- }
302
-
303
- export interface DuckTableSearchInputProps extends React.HTMLProps<HTMLDivElement> {}
304
-
305
- export function DuckTableSearchInput({ className, ...props }: DuckTableSearchInputProps) {
306
- return (
307
- <div className={cn('flex-1', className)} {...props}>
308
- <Input placeholder="Search..." />
309
- </div>
310
- )
311
- }
@@ -1,272 +0,0 @@
1
- // @ts-noCheck
2
-
3
- import React from 'react'
4
- import { Button, LabelType } from '../button'
5
- import { ScrollArea } from '../scroll-area'
6
- import { Table, TableBody } from './table'
7
- import { sortArray } from './table.lib'
8
-
9
- // ------------------------------------------------------------------------------------------------
10
- // NOTE: These types are used for the `table-advanced` context.
11
- // ------------------------------------------------------------------------------------------------
12
-
13
- export interface DuckTableProviderProps<TColumnName extends string[]> extends React.HTMLAttributes<HTMLDivElement> {
14
- table_columns: readonly TableColumnType[]
15
- table_rows: TableContentDataType<TColumnName>[]
16
- }
17
-
18
- export type DuckTableContextType<TColumnName extends string[]> = {
19
- tableColumns: Map<string, TableColumnType>
20
- setTableColumns: React.Dispatch<React.SetStateAction<Map<string, TableColumnType>>>
21
- tableRows: TableContentDataType<TColumnName>[]
22
- selectedRows: Set<TableContentDataType<TColumnName>>
23
- setSelectedRows: React.Dispatch<React.SetStateAction<Set<TableContentDataType<TColumnName>>>>
24
- search: TableSearchStateType
25
- setSearch: React.Dispatch<React.SetStateAction<TableSearchStateType>>
26
- }
27
-
28
- export type TableSortByStateType<TColumnName extends string[]> = {
29
- label: TColumnName[number]
30
- type: React.HTMLProps<HTMLDivElement>['aria-sort']
31
- }
32
-
33
- export interface TableSearchStateType {
34
- query: string
35
- queryBy: string[]
36
- }
37
-
38
- // ------------------------------------------------------------------------------------------------
39
- // NOTE: These types are used for the `table-advanced` Components.
40
- // ------------------------------------------------------------------------------------------------
41
-
42
- /**
43
- * Interface for the `DuckTable` component
44
- */
45
- export interface DuckTableProps extends React.ComponentPropsWithoutRef<typeof Table> {
46
- wrapper?: React.ComponentPropsWithoutRef<typeof ScrollArea>
47
- }
48
-
49
- /**
50
- * Interface for the `DuckTableHeader` component
51
- */
52
- export interface DuckTableHeaderProps {}
53
-
54
- /**
55
- * Interface for the `DuckTableHeadCheckbox` component
56
- */
57
- export interface DuckTableHeadCheckboxProps extends React.HTMLProps<HTMLDivElement> {}
58
-
59
- /**
60
- * Interface for the `DuckTableRowCheckbox` component
61
- */
62
- export interface DuckTableRowCheckboxProps<TColumnName extends readonly TableColumnType[]>
63
- extends React.HTMLProps<HTMLDivElement> {
64
- tableRow: TableContentDataType<GetColumnLabel<TColumnName>>
65
- }
66
-
67
- /**
68
- * Interface for the `DuckTableHeadSelectable` component
69
- */
70
- export interface DuckTableHeadSelectableProps<TSort extends boolean = true> extends React.HTMLProps<HTMLDivElement> {
71
- column: TableColumnType<TSort>
72
- label: string
73
- showLabel?: boolean | undefined
74
- }
75
-
76
- /**
77
- * Interface for the `DuckTableBody` component
78
- */
79
- export interface DuckTableBodyProps extends React.ComponentPropsWithoutRef<typeof TableBody> {}
80
-
81
- // ------------------------------------------------------------------------------------------------
82
- // NOTE: These types are used for the `table-advanced, hence i use them to get the types.
83
- // ------------------------------------------------------------------------------------------------
84
-
85
- /**
86
- * Extracts the `label` property from an array of `TableColumnType` objects
87
- * and returns a tuple of string literals representing the column labels.
88
- *
89
- * ### Type Safety Guidelines:
90
- * 1. Ensure the `columns` array is defined as `const` to preserve type inference.
91
- * 2. Use `readonly TableColumnType[]` to enforce immutability and proper inference.
92
- *
93
- * #### Inferring Labels as a Union
94
- * - Append `[number]` to the type to extract a union of possible labels.
95
- * ```ts
96
- * type ColumnLabel = GetColumnLabel<typeof columns>[number]; // 'Name' | 'Age' | 'Email'
97
- * ```
98
- *
99
- * #### Defining Columns and Extracting Labels
100
- * ```ts
101
- * // Define columns as a strongly typed readonly array
102
- * const columns = [
103
- * { label: "Name" },
104
- * { label: "Age" },
105
- * { label: "Email" }
106
- * ] as const satisfies readonly TableColumnType[];
107
- *
108
- * // Extract column labels as a tuple of string literals
109
- * type ColumnLabels = GetColumnLabel<typeof columns>; // ['Name', 'Age', 'Email']
110
- * ```
111
- */
112
- export type GetColumnLabel<TColumn extends readonly TableColumnType[]> = {
113
- -readonly [K in keyof TColumn]: `${TColumn[K]['label']}`
114
- }
115
-
116
- /**
117
- * Defines the column type for a table based on a dynamic set of column names.
118
- *
119
- * ### Type Safety Guidelines:
120
- * 1. Define the columns array as `const` to infer the most precise type.
121
- * 2. Ensure the type satisfies `readonly string[]` to preserve strict type checking.
122
- *
123
- * #### Inferring Column Names as a Union
124
- * - Append `[number]` to the type to infer a union of possible column names.
125
- * ```ts
126
- * type ColumnName = TColumnName[number]; // Infers as a union of column names
127
- * ```
128
- *
129
- * #### Defining Columns and Extracting Names
130
- * ```ts
131
- * // Define column names as a strongly typed readonly array
132
- * const columnNames = ['name', 'age', 'email'] as const;
133
- *
134
- * // Extract column names as a union type
135
- * type ColumnName = typeof columnNames[number]; // 'name' | 'age' | 'email'
136
- * ```
137
- *
138
- * #### Example Usage
139
- * ```ts
140
- * type MyTableColumns = TableContentDataType<typeof columnNames>;
141
- *
142
- * const columns: MyTableColumns = {
143
- * name: { label: "Full Name", children: "firstName", icon: { name: "user" } },
144
- * age: { label: "Age", icon: { name: "calendar" } },
145
- * email: { label: "Email Address" }
146
- * };
147
- * ```
148
- */
149
- export type TableContentDataType<TColumnName extends readonly string[]> = {
150
- [key in TColumnName[number]]: TableColumnType & {
151
- children?: TColumnName[number]
152
- icon?: React.ReactNode
153
- }
154
- }
155
-
156
- /**
157
- * **Utility Type: Mutable**
158
- * Converts all properties of a type `T` from readonly to mutable.
159
- *
160
- * @template T - The type to make mutable.
161
- *
162
- * @example
163
- * ```ts
164
- * type ReadonlyUser = { readonly name: string; readonly age: number };
165
- * type MutableUser = Mutable<ReadonlyUser>;
166
- * // Result:
167
- * // {
168
- * // name: string;
169
- * // age: number;
170
- * // }
171
- * ```
172
- */
173
- export type Mutable<T> = {
174
- -readonly [K in keyof T]: T[K]
175
- } & {}
176
-
177
- /**
178
- * **Utility Type: Immutable**
179
- * Converts all properties of a type `T` from mutable to readonly.
180
- *
181
- * @template T - The type to make immutable.
182
- *
183
- * @example
184
- * ```ts
185
- * type User = { name: string; age: number };
186
- * type ReadonlyUser = Immutable<User>;
187
- * // Result:
188
- * // {
189
- * // readonly name: string;
190
- * // readonly age: number;
191
- * // }
192
- * ```
193
- */
194
- export type Immutable<T> = {
195
- readonly [K in keyof T]: T[K]
196
- } & {}
197
-
198
- /**
199
- * **Utility Type: Mapped**
200
- * A type that directly maps all keys of a given type `T` to themselves.
201
- *
202
- * @template T - The type to map.
203
- *
204
- * @example
205
- * ```ts
206
- * type User = { name: string; age: number };
207
- * type MappedUser = Mapped<User>;
208
- * // Result (Same as User):
209
- * // {
210
- * // name: string;
211
- * // age: number;
212
- * // }
213
- * ```
214
- */
215
- export type Mapped<T> = {
216
- [K in keyof T]: T[K]
217
- } & {}
218
-
219
- // ------------------------------------------------------------------------------------------------
220
- // NOTE: These types are used for the `table-advanced, constants.
221
- // ------------------------------------------------------------------------------------------------
222
-
223
- export type TableColumnSortableType = React.ComponentPropsWithoutRef<typeof Button> & {
224
- children: React.HTMLProps<HTMLDivElement>['aria-sort']
225
- }
226
-
227
- // ------------------------------------------------------------------------------------------------
228
-
229
- export interface TableColumnType<TSort extends boolean = true> extends Partial<React.HTMLProps<HTMLTableCellElement>> {
230
- label: string
231
- sortable?: boolean
232
- showLabel?: boolean
233
- }
234
-
235
- export interface TableDropdownMenuOptionsType<T extends boolean> {
236
- sortArray: typeof sortArray
237
- setHeaders: React.Dispatch<React.SetStateAction<TableColumnType[]>>
238
- headers: TableColumnType[]
239
- tableData: TableContentDataType<T>[]
240
- setTableData: React.Dispatch<React.SetStateAction<TableContentDataType<T>[]>>
241
- data: TableContentDataType<T>[]
242
- idx: number
243
- column: TableColumnType
244
- }
245
-
246
- export interface TableColumnType extends React.HTMLProps<HTMLTableCellElement> {
247
- // TODO: clean up these legacy props
248
- // FIX: make sure to use these in the future
249
- withLabel?: Omit<LabelType, 'showCommand' | 'showLabel'>
250
- withIcon?: React.ReactNode
251
- }
252
- // ------------------------------------------------------------------------------------------------
253
- //NOTE: not used yet.
254
- export type TableDataFilteredType<T extends Record<string, unknown>> = {
255
- [K in keyof T]: [K, T[K]]
256
- }[keyof T][]
257
-
258
- export interface TablePaginationStateType {
259
- pageSize: number
260
- pageIndex: number
261
- }
262
-
263
- export interface TableSelectionStateType {
264
- rowSelected: Record<string, unknown>[]
265
- }
266
-
267
- export type ColumnsViewedStateType<T extends Record<string, unknown>> = TableColumnType<T> | null
268
-
269
- export type OrderStateType = {
270
- orderBy: string
271
- orderDir: 'asc' | 'desc'
272
- }
@@ -1,2 +0,0 @@
1
- export const PAGE_SIZE = 6
2
- export const PAGE_INDEX = 0