@teamix-evo/ui 0.4.0 → 0.5.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 +46 -50
- package/manifest.json +406 -653
- package/package.json +15 -34
- package/src/_design-system/theme-tokens/stories.tsx +1474 -0
- package/src/components/accordion/index.tsx +139 -0
- package/src/components/accordion/meta.md +162 -0
- package/src/components/accordion/stories.tsx +145 -0
- package/src/components/affix/index.tsx +149 -0
- package/src/components/affix/meta.md +23 -0
- package/src/components/affix/stories.tsx +70 -0
- package/src/components/alert/index.tsx +220 -0
- package/src/components/alert/meta.md +133 -0
- package/src/components/alert/stories.tsx +126 -0
- package/src/components/alert-dialog/index.tsx +282 -0
- package/src/components/alert-dialog/meta.md +86 -0
- package/src/components/alert-dialog/stories.tsx +163 -0
- package/src/components/avatar/index.tsx +159 -0
- package/src/components/avatar/meta.md +242 -0
- package/src/components/avatar/stories.tsx +241 -0
- package/src/components/badge/index.tsx +299 -0
- package/src/components/badge/meta.md +237 -0
- package/src/components/badge/stories.tsx +275 -0
- package/src/components/breadcrumb/index.tsx +137 -0
- package/src/components/breadcrumb/meta.md +64 -0
- package/src/components/breadcrumb/stories.tsx +86 -0
- package/src/components/button/index.tsx +202 -0
- package/src/components/button/meta.md +209 -0
- package/src/components/button/stories.tsx +215 -0
- package/src/components/button-group/index.tsx +211 -0
- package/src/components/button-group/meta.md +190 -0
- package/src/components/button-group/stories.tsx +182 -0
- package/src/components/calendar/index.tsx +240 -0
- package/src/components/calendar/meta.md +36 -0
- package/src/components/calendar/stories.tsx +36 -0
- package/src/components/card/index.tsx +262 -0
- package/src/components/card/meta.md +194 -0
- package/src/components/card/stories.tsx +202 -0
- package/src/components/carousel/index.tsx +481 -0
- package/src/components/carousel/meta.md +208 -0
- package/src/components/carousel/stories.tsx +271 -0
- package/src/components/cascader-select/index.tsx +308 -0
- package/src/components/cascader-select/meta.md +28 -0
- package/src/components/cascader-select/stories.tsx +118 -0
- package/src/components/checkbox/index.tsx +208 -0
- package/src/components/checkbox/meta.md +166 -0
- package/src/components/checkbox/stories.tsx +206 -0
- package/src/components/collapsible/index.tsx +72 -0
- package/src/components/collapsible/meta.md +87 -0
- package/src/components/collapsible/stories.tsx +97 -0
- package/src/components/color-picker/index.tsx +677 -0
- package/src/components/color-picker/meta.md +83 -0
- package/src/components/color-picker/stories.tsx +172 -0
- package/src/components/combobox/index.tsx +687 -0
- package/src/components/combobox/meta.md +83 -0
- package/src/components/combobox/stories.tsx +179 -0
- package/src/components/command/index.tsx +238 -0
- package/src/components/command/meta.md +48 -0
- package/src/components/command/stories.tsx +83 -0
- package/src/components/data-table/index.tsx +1537 -0
- package/src/components/data-table/meta.md +107 -0
- package/src/components/data-table/stories.tsx +1234 -0
- package/src/components/date-picker/index.tsx +1492 -0
- package/src/components/date-picker/meta.md +103 -0
- package/src/components/date-picker/stories.tsx +125 -0
- package/src/components/descriptions/index.tsx +535 -0
- package/src/components/descriptions/meta.md +104 -0
- package/src/components/descriptions/stories.tsx +389 -0
- package/src/components/dialog/index.tsx +255 -0
- package/src/components/dialog/meta.md +244 -0
- package/src/components/dialog/stories.tsx +330 -0
- package/src/components/dropdown-menu/index.tsx +301 -0
- package/src/components/dropdown-menu/meta.md +93 -0
- package/src/components/dropdown-menu/stories.tsx +124 -0
- package/src/components/empty/index.tsx +431 -0
- package/src/components/empty/meta.md +274 -0
- package/src/components/empty/stories.tsx +278 -0
- package/src/components/field/index.tsx +374 -0
- package/src/components/field/meta.md +283 -0
- package/src/components/field/stories.tsx +327 -0
- package/src/components/filter-bar/index.tsx +976 -0
- package/src/components/filter-bar/meta.md +57 -0
- package/src/components/filter-bar/stories.tsx +496 -0
- package/src/components/float-button/index.tsx +163 -0
- package/src/components/float-button/meta.md +73 -0
- package/src/components/float-button/stories.tsx +68 -0
- package/src/components/form/index.tsx +218 -0
- package/src/components/form/meta.md +16 -0
- package/src/components/form/stories.tsx +301 -0
- package/src/components/hover-card/index.tsx +103 -0
- package/src/components/hover-card/meta.md +71 -0
- package/src/components/hover-card/stories.tsx +107 -0
- package/src/components/icon/index.tsx +225 -0
- package/src/components/icon/meta.md +102 -0
- package/src/components/icon/stories.tsx +127 -0
- package/src/components/image/index.tsx +147 -0
- package/src/components/image/meta.md +55 -0
- package/src/components/image/stories.tsx +48 -0
- package/src/components/input/index.tsx +63 -0
- package/src/components/input/meta.md +57 -0
- package/src/components/input/stories.tsx +66 -0
- package/src/components/input-group/index.tsx +292 -0
- package/src/components/input-group/meta.md +108 -0
- package/src/components/input-group/stories.tsx +258 -0
- package/src/components/input-ip/index.tsx +288 -0
- package/src/components/input-ip/meta.md +48 -0
- package/src/components/input-ip/stories.tsx +69 -0
- package/src/components/input-number/index.tsx +360 -0
- package/src/components/input-number/meta.md +156 -0
- package/src/components/input-number/stories.tsx +187 -0
- package/src/components/item/index.tsx +368 -0
- package/src/components/item/meta.md +395 -0
- package/src/components/item/stories.tsx +432 -0
- package/src/components/label/index.tsx +44 -0
- package/src/components/label/meta.md +68 -0
- package/src/components/label/stories.tsx +64 -0
- package/src/components/mentions/index.tsx +369 -0
- package/src/components/mentions/meta.md +118 -0
- package/src/components/mentions/stories.tsx +153 -0
- package/src/components/menubar/index.tsx +313 -0
- package/src/components/menubar/meta.md +52 -0
- package/src/components/menubar/stories.tsx +99 -0
- package/src/components/navigation-menu/index.tsx +216 -0
- package/src/components/navigation-menu/meta.md +66 -0
- package/src/components/navigation-menu/stories.tsx +137 -0
- package/src/components/page-header/index.tsx +218 -0
- package/src/components/page-header/meta.md +211 -0
- package/src/components/page-header/stories.tsx +290 -0
- package/src/components/page-shell/index.tsx +119 -0
- package/src/components/page-shell/meta.md +115 -0
- package/src/components/page-shell/stories.tsx +154 -0
- package/src/components/pagination/index.tsx +580 -0
- package/src/components/pagination/meta.md +39 -0
- package/src/components/pagination/stories.tsx +319 -0
- package/src/components/popconfirm/index.tsx +477 -0
- package/src/components/popconfirm/meta.md +164 -0
- package/src/components/popconfirm/stories.tsx +231 -0
- package/src/components/popover/index.tsx +181 -0
- package/src/components/popover/meta.md +97 -0
- package/src/components/popover/stories.tsx +169 -0
- package/src/components/progress/index.tsx +176 -0
- package/src/components/progress/meta.md +95 -0
- package/src/components/progress/stories.tsx +115 -0
- package/src/components/radio-group/index.tsx +78 -0
- package/src/components/radio-group/meta.md +137 -0
- package/src/components/radio-group/stories.tsx +285 -0
- package/src/components/rate/index.tsx +284 -0
- package/src/components/rate/meta.md +63 -0
- package/src/components/rate/stories.tsx +107 -0
- package/src/components/resizable/index.tsx +122 -0
- package/src/components/resizable/meta.md +142 -0
- package/src/components/resizable/stories.tsx +105 -0
- package/src/components/scroll-area/index.tsx +83 -0
- package/src/components/scroll-area/meta.md +85 -0
- package/src/components/scroll-area/stories.tsx +82 -0
- package/src/components/select/index.tsx +325 -0
- package/src/components/select/meta.md +183 -0
- package/src/components/select/stories.tsx +210 -0
- package/src/components/separator/index.tsx +51 -0
- package/src/components/separator/meta.md +68 -0
- package/src/components/separator/stories.tsx +53 -0
- package/src/components/sheet/index.tsx +293 -0
- package/src/components/sheet/meta.md +226 -0
- package/src/components/sheet/stories.tsx +405 -0
- package/src/components/sidebar/index.tsx +715 -0
- package/src/components/sidebar/meta.md +14 -0
- package/src/components/sidebar/{sidebar.stories.tsx → stories.tsx} +250 -330
- package/src/components/skeleton/index.tsx +415 -0
- package/src/components/skeleton/meta.md +210 -0
- package/src/components/skeleton/stories.tsx +197 -0
- package/src/components/slider/index.tsx +222 -0
- package/src/components/slider/meta.md +125 -0
- package/src/components/slider/stories.tsx +109 -0
- package/src/components/sonner/index.tsx +149 -0
- package/src/components/sonner/meta.md +156 -0
- package/src/components/sonner/stories.tsx +285 -0
- package/src/components/spinner/index.tsx +335 -0
- package/src/components/spinner/meta.md +172 -0
- package/src/components/spinner/stories.tsx +197 -0
- package/src/components/statistic/{statistic.tsx → index.tsx} +25 -26
- package/src/components/statistic/meta.md +94 -0
- package/src/components/statistic/stories.tsx +85 -0
- package/src/components/steps/index.tsx +500 -0
- package/src/components/steps/meta.md +245 -0
- package/src/components/steps/stories.tsx +287 -0
- package/src/components/switch/index.tsx +175 -0
- package/src/components/switch/meta.md +107 -0
- package/src/components/switch/stories.tsx +154 -0
- package/src/components/table/index.tsx +350 -0
- package/src/components/table/meta.md +148 -0
- package/src/components/table/stories.tsx +189 -0
- package/src/components/tabs/index.tsx +379 -0
- package/src/components/tabs/meta.md +244 -0
- package/src/components/tabs/stories.tsx +312 -0
- package/src/components/tag/index.tsx +774 -0
- package/src/components/tag/meta.md +256 -0
- package/src/components/tag/stories.tsx +431 -0
- package/src/components/textarea/index.tsx +62 -0
- package/src/components/textarea/meta.md +77 -0
- package/src/components/textarea/stories.tsx +112 -0
- package/src/components/time-picker/index.tsx +887 -0
- package/src/components/time-picker/meta.md +102 -0
- package/src/components/time-picker/stories.tsx +125 -0
- package/src/components/timeline/index.tsx +422 -0
- package/src/components/timeline/meta.md +352 -0
- package/src/components/timeline/stories.tsx +369 -0
- package/src/components/toggle/index.tsx +74 -0
- package/src/components/toggle/meta.md +76 -0
- package/src/components/toggle/stories.tsx +66 -0
- package/src/components/toggle-group/index.tsx +167 -0
- package/src/components/toggle-group/meta.md +141 -0
- package/src/components/toggle-group/stories.tsx +124 -0
- package/src/components/tooltip/index.tsx +144 -0
- package/src/components/tooltip/meta.md +186 -0
- package/src/components/tooltip/stories.tsx +212 -0
- package/src/components/transfer/index.tsx +639 -0
- package/src/components/transfer/meta.md +76 -0
- package/src/components/transfer/stories.tsx +221 -0
- package/src/components/tree/index.tsx +764 -0
- package/src/components/tree/meta.md +96 -0
- package/src/components/tree/stories.tsx +385 -0
- package/src/components/tree/utils.ts +269 -0
- package/src/components/tree-select/index.tsx +400 -0
- package/src/components/tree-select/meta.md +78 -0
- package/src/components/tree-select/stories.tsx +234 -0
- package/src/components/typography/index.tsx +290 -0
- package/src/components/typography/meta.md +151 -0
- package/src/components/typography/stories.tsx +151 -0
- package/src/components/upload/index.tsx +858 -0
- package/src/components/upload/meta.md +122 -0
- package/src/components/upload/stories.tsx +261 -0
- package/src/components/watermark/index.tsx +152 -0
- package/src/components/watermark/meta.md +67 -0
- package/src/components/watermark/stories.tsx +59 -0
- package/src/hooks/use-mobile.ts +9 -11
- package/src/lib/color.ts +243 -0
- package/src/{utils/cn.ts → lib/utils.ts} +1 -1
- package/src/components/accordion/accordion.meta.md +0 -88
- package/src/components/accordion/accordion.stories.tsx +0 -72
- package/src/components/accordion/accordion.tsx +0 -154
- package/src/components/affix/affix.meta.md +0 -98
- package/src/components/affix/affix.stories.tsx +0 -134
- package/src/components/affix/affix.tsx +0 -167
- package/src/components/alert/alert.meta.md +0 -132
- package/src/components/alert/alert.stories.tsx +0 -138
- package/src/components/alert/alert.tsx +0 -179
- package/src/components/alert-dialog/alert-dialog.meta.md +0 -152
- package/src/components/alert-dialog/alert-dialog.stories.tsx +0 -223
- package/src/components/alert-dialog/alert-dialog.tsx +0 -183
- package/src/components/anchor/anchor.meta.md +0 -92
- package/src/components/anchor/anchor.stories.tsx +0 -74
- package/src/components/anchor/anchor.tsx +0 -130
- package/src/components/app/app.meta.md +0 -91
- package/src/components/app/app.stories.tsx +0 -64
- package/src/components/app/app.tsx +0 -58
- package/src/components/aspect-ratio/aspect-ratio.meta.md +0 -82
- package/src/components/aspect-ratio/aspect-ratio.stories.tsx +0 -59
- package/src/components/aspect-ratio/aspect-ratio.tsx +0 -22
- package/src/components/auto-complete/auto-complete.meta.md +0 -110
- package/src/components/auto-complete/auto-complete.stories.tsx +0 -136
- package/src/components/auto-complete/auto-complete.tsx +0 -253
- package/src/components/avatar/avatar.meta.md +0 -93
- package/src/components/avatar/avatar.stories.tsx +0 -98
- package/src/components/avatar/avatar.tsx +0 -127
- package/src/components/badge/badge.meta.md +0 -120
- package/src/components/badge/badge.stories.tsx +0 -153
- package/src/components/badge/badge.tsx +0 -204
- package/src/components/breadcrumb/breadcrumb.meta.md +0 -127
- package/src/components/breadcrumb/breadcrumb.stories.tsx +0 -207
- package/src/components/breadcrumb/breadcrumb.tsx +0 -136
- package/src/components/button/button.meta.md +0 -335
- package/src/components/button/button.stories.tsx +0 -743
- package/src/components/button/button.tsx +0 -466
- package/src/components/calendar/calendar.meta.md +0 -128
- package/src/components/calendar/calendar.stories.tsx +0 -68
- package/src/components/calendar/calendar.tsx +0 -172
- package/src/components/card/card.meta.md +0 -139
- package/src/components/card/card.stories.tsx +0 -151
- package/src/components/card/card.tsx +0 -306
- package/src/components/carousel/carousel.meta.md +0 -118
- package/src/components/carousel/carousel.stories.tsx +0 -89
- package/src/components/carousel/carousel.tsx +0 -224
- package/src/components/cascader/cascader.meta.md +0 -140
- package/src/components/cascader/cascader.stories.tsx +0 -120
- package/src/components/cascader/cascader.tsx +0 -548
- package/src/components/checkbox/checkbox.meta.md +0 -167
- package/src/components/checkbox/checkbox.stories.tsx +0 -288
- package/src/components/checkbox/checkbox.tsx +0 -195
- package/src/components/collapsible/collapsible.meta.md +0 -88
- package/src/components/collapsible/collapsible.stories.tsx +0 -43
- package/src/components/collapsible/collapsible.tsx +0 -105
- package/src/components/color-picker/color-picker.meta.md +0 -89
- package/src/components/color-picker/color-picker.stories.tsx +0 -159
- package/src/components/color-picker/color-picker.tsx +0 -171
- package/src/components/command/command.meta.md +0 -120
- package/src/components/command/command.stories.tsx +0 -59
- package/src/components/command/command.tsx +0 -158
- package/src/components/context-menu/context-menu.meta.md +0 -93
- package/src/components/context-menu/context-menu.stories.tsx +0 -54
- package/src/components/context-menu/context-menu.tsx +0 -204
- package/src/components/data-table/data-table.meta.md +0 -150
- package/src/components/data-table/data-table.stories.tsx +0 -132
- package/src/components/data-table/data-table.tsx +0 -185
- package/src/components/date-picker/date-picker.meta.md +0 -175
- package/src/components/date-picker/date-picker.stories.tsx +0 -108
- package/src/components/date-picker/date-picker.tsx +0 -1554
- package/src/components/descriptions/descriptions.meta.md +0 -83
- package/src/components/descriptions/descriptions.stories.tsx +0 -60
- package/src/components/descriptions/descriptions.tsx +0 -137
- package/src/components/dialog/dialog.meta.md +0 -168
- package/src/components/dialog/dialog.stories.tsx +0 -255
- package/src/components/dialog/dialog.tsx +0 -180
- package/src/components/dialog/imperative.tsx +0 -252
- package/src/components/drawer/drawer.meta.md +0 -95
- package/src/components/drawer/drawer.stories.tsx +0 -71
- package/src/components/drawer/drawer.tsx +0 -23
- package/src/components/dropdown-menu/dropdown-menu.meta.md +0 -171
- package/src/components/dropdown-menu/dropdown-menu.stories.tsx +0 -198
- package/src/components/dropdown-menu/dropdown-menu.tsx +0 -209
- package/src/components/ellipsis/ellipsis.meta.md +0 -87
- package/src/components/ellipsis/ellipsis.stories.tsx +0 -72
- package/src/components/ellipsis/ellipsis.tsx +0 -153
- package/src/components/empty/empty.meta.md +0 -86
- package/src/components/empty/empty.stories.tsx +0 -46
- package/src/components/empty/empty.tsx +0 -54
- package/src/components/field/field.meta.md +0 -154
- package/src/components/field/field.stories.tsx +0 -497
- package/src/components/field/field.tsx +0 -392
- package/src/components/filter-bar/filter-bar.meta.md +0 -92
- package/src/components/filter-bar/filter-bar.stories.tsx +0 -1086
- package/src/components/filter-bar/filter-bar.tsx +0 -568
- package/src/components/flex/flex.meta.md +0 -142
- package/src/components/flex/flex.stories.tsx +0 -199
- package/src/components/flex/flex.tsx +0 -145
- package/src/components/float-button/float-button.meta.md +0 -92
- package/src/components/float-button/float-button.stories.tsx +0 -80
- package/src/components/float-button/float-button.tsx +0 -143
- package/src/components/form/form.meta.md +0 -153
- package/src/components/form/form.stories.tsx +0 -472
- package/src/components/form/form.tsx +0 -260
- package/src/components/grid/grid.meta.md +0 -92
- package/src/components/grid/grid.stories.tsx +0 -101
- package/src/components/grid/grid.tsx +0 -130
- package/src/components/hover-card/hover-card.meta.md +0 -103
- package/src/components/hover-card/hover-card.stories.tsx +0 -97
- package/src/components/hover-card/hover-card.tsx +0 -67
- package/src/components/icon/DEVELOPMENT.md +0 -809
- package/src/components/icon/icon.meta.md +0 -170
- package/src/components/icon/icon.stories.tsx +0 -344
- package/src/components/icon/icon.tsx +0 -248
- package/src/components/image/image.meta.md +0 -99
- package/src/components/image/image.stories.tsx +0 -55
- package/src/components/image/image.tsx +0 -140
- package/src/components/input/input.meta.md +0 -115
- package/src/components/input/input.stories.tsx +0 -144
- package/src/components/input/input.tsx +0 -212
- package/src/components/input-group/input-group.meta.md +0 -124
- package/src/components/input-group/input-group.stories.tsx +0 -121
- package/src/components/input-group/input-group.tsx +0 -143
- package/src/components/input-number/input-number.meta.md +0 -148
- package/src/components/input-number/input-number.stories.tsx +0 -125
- package/src/components/input-number/input-number.tsx +0 -283
- package/src/components/input-otp/input-otp.meta.md +0 -106
- package/src/components/input-otp/input-otp.stories.tsx +0 -65
- package/src/components/input-otp/input-otp.tsx +0 -97
- package/src/components/item/item.meta.md +0 -121
- package/src/components/item/item.stories.tsx +0 -116
- package/src/components/item/item.tsx +0 -172
- package/src/components/kbd/kbd.meta.md +0 -94
- package/src/components/kbd/kbd.stories.tsx +0 -70
- package/src/components/kbd/kbd.tsx +0 -86
- package/src/components/label/label.meta.md +0 -99
- package/src/components/label/label.stories.tsx +0 -145
- package/src/components/label/label.tsx +0 -138
- package/src/components/masonry/masonry.meta.md +0 -90
- package/src/components/masonry/masonry.stories.tsx +0 -68
- package/src/components/masonry/masonry.tsx +0 -60
- package/src/components/mentions/mentions.meta.md +0 -119
- package/src/components/mentions/mentions.stories.tsx +0 -189
- package/src/components/mentions/mentions.tsx +0 -243
- package/src/components/menubar/menubar.meta.md +0 -118
- package/src/components/menubar/menubar.stories.tsx +0 -141
- package/src/components/menubar/menubar.tsx +0 -232
- package/src/components/native-select/native-select.meta.md +0 -93
- package/src/components/native-select/native-select.stories.tsx +0 -83
- package/src/components/native-select/native-select.tsx +0 -54
- package/src/components/navigation-menu/navigation-menu.meta.md +0 -118
- package/src/components/navigation-menu/navigation-menu.stories.tsx +0 -215
- package/src/components/navigation-menu/navigation-menu.tsx +0 -129
- package/src/components/notification/notification.meta.md +0 -133
- package/src/components/notification/notification.stories.tsx +0 -98
- package/src/components/notification/notification.tsx +0 -99
- package/src/components/page-header/DEVELOPMENT.md +0 -842
- package/src/components/page-header/page-header.meta.md +0 -210
- package/src/components/page-header/page-header.stories.tsx +0 -428
- package/src/components/page-header/page-header.tsx +0 -284
- package/src/components/page-shell/page-shell.meta.md +0 -116
- package/src/components/page-shell/page-shell.stories.tsx +0 -149
- package/src/components/page-shell/page-shell.tsx +0 -115
- package/src/components/pagination/pagination.meta.md +0 -230
- package/src/components/pagination/pagination.stories.tsx +0 -284
- package/src/components/pagination/pagination.tsx +0 -567
- package/src/components/popconfirm/popconfirm.meta.md +0 -114
- package/src/components/popconfirm/popconfirm.stories.tsx +0 -75
- package/src/components/popconfirm/popconfirm.tsx +0 -134
- package/src/components/popover/popover.meta.md +0 -154
- package/src/components/popover/popover.stories.tsx +0 -158
- package/src/components/popover/popover.tsx +0 -104
- package/src/components/progress/progress.meta.md +0 -118
- package/src/components/progress/progress.stories.tsx +0 -75
- package/src/components/progress/progress.tsx +0 -203
- package/src/components/radio-group/radio-group.meta.md +0 -175
- package/src/components/radio-group/radio-group.stories.tsx +0 -113
- package/src/components/radio-group/radio-group.tsx +0 -209
- package/src/components/rate/rate.meta.md +0 -118
- package/src/components/rate/rate.stories.tsx +0 -89
- package/src/components/rate/rate.tsx +0 -180
- package/src/components/resizable/resizable.meta.md +0 -95
- package/src/components/resizable/resizable.stories.tsx +0 -104
- package/src/components/resizable/resizable.tsx +0 -56
- package/src/components/result/result.meta.md +0 -95
- package/src/components/result/result.stories.tsx +0 -67
- package/src/components/result/result.tsx +0 -100
- package/src/components/scroll-area/scroll-area.meta.md +0 -85
- package/src/components/scroll-area/scroll-area.stories.tsx +0 -49
- package/src/components/scroll-area/scroll-area.tsx +0 -51
- package/src/components/segmented/segmented.meta.md +0 -106
- package/src/components/segmented/segmented.stories.tsx +0 -130
- package/src/components/segmented/segmented.tsx +0 -146
- package/src/components/select/select.meta.md +0 -255
- package/src/components/select/select.stories.tsx +0 -275
- package/src/components/select/select.tsx +0 -735
- package/src/components/separator/separator.meta.md +0 -75
- package/src/components/separator/separator.stories.tsx +0 -71
- package/src/components/separator/separator.tsx +0 -100
- package/src/components/sheet/sheet.meta.md +0 -113
- package/src/components/sheet/sheet.stories.tsx +0 -188
- package/src/components/sheet/sheet.tsx +0 -226
- package/src/components/sidebar/sidebar.meta.md +0 -151
- package/src/components/sidebar/sidebar.tsx +0 -853
- package/src/components/skeleton/skeleton.meta.md +0 -94
- package/src/components/skeleton/skeleton.stories.tsx +0 -79
- package/src/components/skeleton/skeleton.tsx +0 -144
- package/src/components/slider/slider.meta.md +0 -146
- package/src/components/slider/slider.stories.tsx +0 -121
- package/src/components/slider/slider.tsx +0 -227
- package/src/components/sonner/sonner.meta.md +0 -147
- package/src/components/sonner/sonner.stories.tsx +0 -164
- package/src/components/sonner/sonner.tsx +0 -169
- package/src/components/spinner/spinner.meta.md +0 -125
- package/src/components/spinner/spinner.stories.tsx +0 -123
- package/src/components/spinner/spinner.tsx +0 -166
- package/src/components/statistic/statistic.meta.md +0 -104
- package/src/components/statistic/statistic.stories.tsx +0 -67
- package/src/components/steps/steps.meta.md +0 -116
- package/src/components/steps/steps.stories.tsx +0 -115
- package/src/components/steps/steps.tsx +0 -173
- package/src/components/switch/switch.meta.md +0 -138
- package/src/components/switch/switch.stories.tsx +0 -75
- package/src/components/switch/switch.tsx +0 -169
- package/src/components/table/table.meta.md +0 -106
- package/src/components/table/table.stories.tsx +0 -80
- package/src/components/table/table.tsx +0 -124
- package/src/components/tabs/tabs.meta.md +0 -111
- package/src/components/tabs/tabs.stories.tsx +0 -156
- package/src/components/tabs/tabs.tsx +0 -190
- package/src/components/tag/tag.meta.md +0 -159
- package/src/components/tag/tag.stories.tsx +0 -250
- package/src/components/tag/tag.tsx +0 -386
- package/src/components/textarea/textarea.meta.md +0 -99
- package/src/components/textarea/textarea.stories.tsx +0 -89
- package/src/components/textarea/textarea.tsx +0 -137
- package/src/components/time-picker/time-picker.meta.md +0 -175
- package/src/components/time-picker/time-picker.stories.tsx +0 -129
- package/src/components/time-picker/time-picker.tsx +0 -946
- package/src/components/timeline/timeline.meta.md +0 -110
- package/src/components/timeline/timeline.stories.tsx +0 -134
- package/src/components/timeline/timeline.tsx +0 -168
- package/src/components/toggle/toggle.meta.md +0 -89
- package/src/components/toggle/toggle.stories.tsx +0 -66
- package/src/components/toggle/toggle.tsx +0 -54
- package/src/components/toggle-group/toggle-group.meta.md +0 -91
- package/src/components/toggle-group/toggle-group.stories.tsx +0 -83
- package/src/components/toggle-group/toggle-group.tsx +0 -78
- package/src/components/tooltip/tooltip.meta.md +0 -149
- package/src/components/tooltip/tooltip.stories.tsx +0 -108
- package/src/components/tooltip/tooltip.tsx +0 -153
- package/src/components/tour/tour.meta.md +0 -121
- package/src/components/tour/tour.stories.tsx +0 -66
- package/src/components/tour/tour.tsx +0 -242
- package/src/components/transfer/transfer.meta.md +0 -95
- package/src/components/transfer/transfer.stories.tsx +0 -64
- package/src/components/transfer/transfer.tsx +0 -258
- package/src/components/tree/tree.meta.md +0 -169
- package/src/components/tree/tree.stories.tsx +0 -128
- package/src/components/tree/tree.tsx +0 -368
- package/src/components/tree-select/tree-select.meta.md +0 -151
- package/src/components/tree-select/tree-select.stories.tsx +0 -80
- package/src/components/tree-select/tree-select.tsx +0 -206
- package/src/components/typography/typography.meta.md +0 -149
- package/src/components/typography/typography.stories.tsx +0 -116
- package/src/components/typography/typography.tsx +0 -260
- package/src/components/upload/upload.meta.md +0 -156
- package/src/components/upload/upload.stories.tsx +0 -135
- package/src/components/upload/upload.tsx +0 -398
- package/src/components/watermark/watermark.meta.md +0 -100
- package/src/components/watermark/watermark.stories.tsx +0 -170
- package/src/components/watermark/watermark.tsx +0 -166
- package/src/hooks/use-breakpoint.ts +0 -117
- package/src/hooks/use-debounce-callback.ts +0 -52
- package/src/stories/theme-tokens.stories.tsx +0 -747
- package/src/utils/trigger-input.ts +0 -57
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
/* eslint-disable teamix-evo/no-color-literal -- ColorPicker inherently deals with color hex values as its core functionality */
|
|
2
|
+
/**
|
|
3
|
+
* 颜色选择器 ColorPicker
|
|
4
|
+
*
|
|
5
|
+
* 完整的颜色选取器 — 色相/饱和度/明度面板 + 色相滑条 + 透明度滑条 +
|
|
6
|
+
* 格式切换 (hex/rgb/hsb) + 预设色板分组,支持受控/非受控、自定义触发器。
|
|
7
|
+
*
|
|
8
|
+
* @when
|
|
9
|
+
* - 主题定制 / 品牌色设置
|
|
10
|
+
* - 图表 / 可视化编辑器中选色
|
|
11
|
+
* - 标签 / 分类颜色标注
|
|
12
|
+
* - 需要精确颜色输入(含 alpha 透明度)时
|
|
13
|
+
*/
|
|
14
|
+
'use client';
|
|
15
|
+
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import { HsvaColorPicker } from 'react-colorful';
|
|
18
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
19
|
+
import { ChevronDownIcon, XIcon } from 'lucide-react';
|
|
20
|
+
|
|
21
|
+
import { cn } from '@/lib/utils';
|
|
22
|
+
import { Color, type HsvaColor } from '@/lib/color';
|
|
23
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/popover';
|
|
24
|
+
import {
|
|
25
|
+
Collapsible,
|
|
26
|
+
CollapsibleContent,
|
|
27
|
+
CollapsibleTrigger,
|
|
28
|
+
} from '@/components/collapsible';
|
|
29
|
+
|
|
30
|
+
// ─── Types ─────────────────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
/** 颜色格式。 */
|
|
33
|
+
type ColorFormat = 'hex' | 'rgb' | 'hsb';
|
|
34
|
+
|
|
35
|
+
/** 预设色组。 */
|
|
36
|
+
interface ColorPresetGroup {
|
|
37
|
+
/** 分组标签。 */
|
|
38
|
+
label: React.ReactNode;
|
|
39
|
+
/** 组内颜色列表。 */
|
|
40
|
+
colors: string[];
|
|
41
|
+
/** 默认展开。@default true */
|
|
42
|
+
defaultOpen?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 预设色板 — 扁平数组或分组数组。 */
|
|
46
|
+
type ColorPresets = string[] | ColorPresetGroup[];
|
|
47
|
+
|
|
48
|
+
// ─── Trigger variants ──────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
const triggerVariants = cva(
|
|
51
|
+
'inline-flex cursor-pointer items-center gap-1.5 rounded-md border border-input bg-background transition-colors hover:border-ring focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
|
|
52
|
+
{
|
|
53
|
+
variants: {
|
|
54
|
+
size: {
|
|
55
|
+
sm: 'h-6 p-0.5',
|
|
56
|
+
default: 'h-7 p-1',
|
|
57
|
+
lg: 'h-8 p-1',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
defaultVariants: { size: 'default' },
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const swatchVariants = cva('shrink-0 rounded-sm', {
|
|
65
|
+
variants: {
|
|
66
|
+
size: {
|
|
67
|
+
sm: 'size-4',
|
|
68
|
+
default: 'size-5',
|
|
69
|
+
lg: 'size-5',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
defaultVariants: { size: 'default' },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ─── Props ─────────────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
interface ColorPickerProps
|
|
78
|
+
extends Omit<
|
|
79
|
+
React.ComponentProps<'div'>,
|
|
80
|
+
'onChange' | 'children' | 'defaultValue'
|
|
81
|
+
>,
|
|
82
|
+
VariantProps<typeof triggerVariants> {
|
|
83
|
+
/** 当前颜色值(受控)。 */
|
|
84
|
+
value?: string | Color;
|
|
85
|
+
/** 默认颜色值。@default "#1677ff" */
|
|
86
|
+
defaultValue?: string | Color;
|
|
87
|
+
/** 颜色格式。@default "hex" */
|
|
88
|
+
format?: ColorFormat;
|
|
89
|
+
/** 默认颜色格式(非受控)。@default "hex" */
|
|
90
|
+
defaultFormat?: ColorFormat;
|
|
91
|
+
/** 格式变化回调。 */
|
|
92
|
+
onFormatChange?: (format: ColorFormat) => void;
|
|
93
|
+
/** 预设色板 — 字符串数组或分组数组。 */
|
|
94
|
+
presets?: ColorPresets;
|
|
95
|
+
/** 是否禁用。@default false */
|
|
96
|
+
disabled?: boolean;
|
|
97
|
+
/** 颜色变化回调(拖拽中持续触发)。 */
|
|
98
|
+
onChange?: (color: Color, hex: string) => void;
|
|
99
|
+
/** 颜色变化完成回调(拖拽松手 / 输入确认后触发)。 */
|
|
100
|
+
onChangeComplete?: (color: Color, hex: string) => void;
|
|
101
|
+
/** 触发器旁显示颜色文本。 */
|
|
102
|
+
showText?: boolean | ((color: Color) => React.ReactNode);
|
|
103
|
+
/** 允许清除。@default false */
|
|
104
|
+
allowClear?: boolean;
|
|
105
|
+
/** 清除回调。 */
|
|
106
|
+
onClear?: () => void;
|
|
107
|
+
/** 禁用透明度通道。@default false */
|
|
108
|
+
disabledAlpha?: boolean;
|
|
109
|
+
/** 受控弹出状态。 */
|
|
110
|
+
open?: boolean;
|
|
111
|
+
/** 弹出状态变化回调。 */
|
|
112
|
+
onOpenChange?: (open: boolean) => void;
|
|
113
|
+
/** 自定义触发器。 */
|
|
114
|
+
children?: React.ReactNode;
|
|
115
|
+
/** 弹出位置。@default "bottom" */
|
|
116
|
+
placement?: 'top' | 'bottom' | 'left' | 'right';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ─── Helpers ───────────────────────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
/** 透明度棋盘格背景 inline style(无法用 Tailwind token 表达)。 */
|
|
122
|
+
const CHECKERBOARD_STYLE: React.CSSProperties = {
|
|
123
|
+
backgroundSize: '8px 8px',
|
|
124
|
+
backgroundPosition: '0 0, 4px 4px',
|
|
125
|
+
backgroundImage:
|
|
126
|
+
'linear-gradient(45deg, var(--color-muted) 25%, transparent 25%, transparent 75%, var(--color-muted) 75%), linear-gradient(45deg, var(--color-muted) 25%, transparent 25%, transparent 75%, var(--color-muted) 75%)',
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const FORMAT_CYCLE: ColorFormat[] = ['hex', 'rgb', 'hsb'];
|
|
130
|
+
|
|
131
|
+
function toColor(input: string | Color | undefined, fallback: string): Color {
|
|
132
|
+
if (!input) return new Color(fallback);
|
|
133
|
+
return input instanceof Color ? input : new Color(input);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const PICKER_STYLE_OVERRIDES = `
|
|
137
|
+
[data-slot="color-picker-canvas"] .react-colorful {
|
|
138
|
+
width: 100% !important;
|
|
139
|
+
height: auto !important;
|
|
140
|
+
gap: 8px !important;
|
|
141
|
+
}
|
|
142
|
+
[data-slot="color-picker-canvas"] .react-colorful__saturation {
|
|
143
|
+
height: 160px !important;
|
|
144
|
+
flex-grow: 0 !important;
|
|
145
|
+
border-radius: 6px !important;
|
|
146
|
+
border-bottom: none !important;
|
|
147
|
+
}
|
|
148
|
+
[data-slot="color-picker-canvas"] .react-colorful__hue,
|
|
149
|
+
[data-slot="color-picker-canvas"] .react-colorful__alpha {
|
|
150
|
+
height: 10px !important;
|
|
151
|
+
border-radius: 9999px !important;
|
|
152
|
+
}
|
|
153
|
+
[data-slot="color-picker-canvas"] .react-colorful__last-control {
|
|
154
|
+
border-radius: 9999px !important;
|
|
155
|
+
}
|
|
156
|
+
[data-slot="color-picker-canvas"] .react-colorful__pointer {
|
|
157
|
+
width: 14px !important;
|
|
158
|
+
height: 14px !important;
|
|
159
|
+
}
|
|
160
|
+
[data-slot="color-picker-canvas"] .color-picker-no-alpha .react-colorful__alpha {
|
|
161
|
+
display: none !important;
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
|
|
165
|
+
function isPresetGroupArray(
|
|
166
|
+
presets: ColorPresets,
|
|
167
|
+
): presets is ColorPresetGroup[] {
|
|
168
|
+
return presets.length > 0 && typeof presets[0] === 'object';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatColorText(color: Color, format: ColorFormat): string {
|
|
172
|
+
switch (format) {
|
|
173
|
+
case 'hex':
|
|
174
|
+
return color.toHexString();
|
|
175
|
+
case 'rgb':
|
|
176
|
+
return color.toRgbString();
|
|
177
|
+
case 'hsb':
|
|
178
|
+
return color.toHsbString();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ─── Sub-components ────────────────────────────────────────────────────────
|
|
183
|
+
|
|
184
|
+
function ColorSwatch({
|
|
185
|
+
color,
|
|
186
|
+
className,
|
|
187
|
+
style,
|
|
188
|
+
...props
|
|
189
|
+
}: React.ComponentProps<'span'> & { color: string }) {
|
|
190
|
+
return (
|
|
191
|
+
<span
|
|
192
|
+
data-slot="color-picker-swatch"
|
|
193
|
+
className={cn('relative overflow-hidden', className)}
|
|
194
|
+
style={{ ...CHECKERBOARD_STYLE, ...style }}
|
|
195
|
+
{...props}
|
|
196
|
+
>
|
|
197
|
+
<span className="absolute inset-0" style={{ backgroundColor: color }} />
|
|
198
|
+
</span>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function FormatInputs({
|
|
203
|
+
color,
|
|
204
|
+
format,
|
|
205
|
+
disabledAlpha,
|
|
206
|
+
onColorChange,
|
|
207
|
+
onChangeComplete,
|
|
208
|
+
}: {
|
|
209
|
+
color: Color;
|
|
210
|
+
format: ColorFormat;
|
|
211
|
+
disabledAlpha: boolean;
|
|
212
|
+
onColorChange: (c: Color) => void;
|
|
213
|
+
onChangeComplete: (c: Color) => void;
|
|
214
|
+
}) {
|
|
215
|
+
const inputClass =
|
|
216
|
+
'h-6 rounded-sm border border-input bg-transparent px-1 text-xs outline-none text-center transition-colors focus:border-ring';
|
|
217
|
+
|
|
218
|
+
const handleCommit = (c: Color) => {
|
|
219
|
+
onColorChange(c);
|
|
220
|
+
onChangeComplete(c);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
if (format === 'hex') {
|
|
224
|
+
return (
|
|
225
|
+
<HexInput
|
|
226
|
+
color={color}
|
|
227
|
+
disabledAlpha={disabledAlpha}
|
|
228
|
+
className={cn(inputClass, disabledAlpha ? 'w-17' : 'w-20')}
|
|
229
|
+
onCommit={handleCommit}
|
|
230
|
+
/>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (format === 'rgb') {
|
|
235
|
+
const { r, g, b, a } = color.toRgb();
|
|
236
|
+
return (
|
|
237
|
+
<div className="flex items-center gap-1">
|
|
238
|
+
<ChannelInput
|
|
239
|
+
label="R"
|
|
240
|
+
value={r}
|
|
241
|
+
max={255}
|
|
242
|
+
className={cn(inputClass, 'w-10')}
|
|
243
|
+
onChange={(v) => handleCommit(new Color({ r: v, g, b, a }))}
|
|
244
|
+
/>
|
|
245
|
+
<ChannelInput
|
|
246
|
+
label="G"
|
|
247
|
+
value={g}
|
|
248
|
+
max={255}
|
|
249
|
+
className={cn(inputClass, 'w-10')}
|
|
250
|
+
onChange={(v) => handleCommit(new Color({ r, g: v, b, a }))}
|
|
251
|
+
/>
|
|
252
|
+
<ChannelInput
|
|
253
|
+
label="B"
|
|
254
|
+
value={b}
|
|
255
|
+
max={255}
|
|
256
|
+
className={cn(inputClass, 'w-10')}
|
|
257
|
+
onChange={(v) => handleCommit(new Color({ r, g, b: v, a }))}
|
|
258
|
+
/>
|
|
259
|
+
{!disabledAlpha && (
|
|
260
|
+
<ChannelInput
|
|
261
|
+
label="A"
|
|
262
|
+
value={Math.round(a * 100)}
|
|
263
|
+
max={100}
|
|
264
|
+
suffix="%"
|
|
265
|
+
className={cn(inputClass, 'w-11')}
|
|
266
|
+
onChange={(v) => {
|
|
267
|
+
const next = color.setAlpha(v / 100);
|
|
268
|
+
handleCommit(next);
|
|
269
|
+
}}
|
|
270
|
+
/>
|
|
271
|
+
)}
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// hsb
|
|
277
|
+
const { h, s, b: bv, a } = color.toHsb();
|
|
278
|
+
return (
|
|
279
|
+
<div className="flex items-center gap-1">
|
|
280
|
+
<ChannelInput
|
|
281
|
+
label="H"
|
|
282
|
+
value={h}
|
|
283
|
+
max={360}
|
|
284
|
+
className={cn(inputClass, 'w-10')}
|
|
285
|
+
onChange={(v) =>
|
|
286
|
+
handleCommit(new Color({ h: v, s, v: bv, a } as HsvaColor))
|
|
287
|
+
}
|
|
288
|
+
/>
|
|
289
|
+
<ChannelInput
|
|
290
|
+
label="S"
|
|
291
|
+
value={s}
|
|
292
|
+
max={100}
|
|
293
|
+
className={cn(inputClass, 'w-10')}
|
|
294
|
+
onChange={(v) =>
|
|
295
|
+
handleCommit(new Color({ h, s: v, v: bv, a } as HsvaColor))
|
|
296
|
+
}
|
|
297
|
+
/>
|
|
298
|
+
<ChannelInput
|
|
299
|
+
label="B"
|
|
300
|
+
value={bv}
|
|
301
|
+
max={100}
|
|
302
|
+
className={cn(inputClass, 'w-10')}
|
|
303
|
+
onChange={(v) => handleCommit(new Color({ h, s, v, a } as HsvaColor))}
|
|
304
|
+
/>
|
|
305
|
+
{!disabledAlpha && (
|
|
306
|
+
<ChannelInput
|
|
307
|
+
label="A"
|
|
308
|
+
value={Math.round(a * 100)}
|
|
309
|
+
max={100}
|
|
310
|
+
suffix="%"
|
|
311
|
+
className={cn(inputClass, 'w-11')}
|
|
312
|
+
onChange={(v) => {
|
|
313
|
+
const next = color.setAlpha(v / 100);
|
|
314
|
+
handleCommit(next);
|
|
315
|
+
}}
|
|
316
|
+
/>
|
|
317
|
+
)}
|
|
318
|
+
</div>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function HexInput({
|
|
323
|
+
color,
|
|
324
|
+
disabledAlpha,
|
|
325
|
+
className,
|
|
326
|
+
onCommit,
|
|
327
|
+
}: {
|
|
328
|
+
color: Color;
|
|
329
|
+
disabledAlpha: boolean;
|
|
330
|
+
className?: string;
|
|
331
|
+
onCommit: (c: Color) => void;
|
|
332
|
+
}) {
|
|
333
|
+
const displayValue = disabledAlpha ? color.toHex() : color.toHexString();
|
|
334
|
+
const [draft, setDraft] = React.useState(displayValue);
|
|
335
|
+
const [focused, setFocused] = React.useState(false);
|
|
336
|
+
|
|
337
|
+
React.useEffect(() => {
|
|
338
|
+
if (!focused) setDraft(displayValue);
|
|
339
|
+
}, [displayValue, focused]);
|
|
340
|
+
|
|
341
|
+
const confirm = () => {
|
|
342
|
+
const hex = draft.startsWith('#') ? draft : `#${draft}`;
|
|
343
|
+
const parsed = new Color(hex);
|
|
344
|
+
if (
|
|
345
|
+
parsed.toHex() !== '#000000' ||
|
|
346
|
+
hex.toLowerCase() === '#000000' ||
|
|
347
|
+
hex.toLowerCase() === '#000'
|
|
348
|
+
) {
|
|
349
|
+
onCommit(disabledAlpha ? parsed.setAlpha(1) : parsed);
|
|
350
|
+
}
|
|
351
|
+
setFocused(false);
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<input
|
|
356
|
+
data-slot="color-picker-hex-input"
|
|
357
|
+
type="text"
|
|
358
|
+
value={focused ? draft : displayValue}
|
|
359
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
360
|
+
onFocus={() => setFocused(true)}
|
|
361
|
+
onBlur={confirm}
|
|
362
|
+
onKeyDown={(e) => e.key === 'Enter' && confirm()}
|
|
363
|
+
className={className}
|
|
364
|
+
/>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function ChannelInput({
|
|
369
|
+
label,
|
|
370
|
+
value,
|
|
371
|
+
max,
|
|
372
|
+
suffix,
|
|
373
|
+
className,
|
|
374
|
+
onChange,
|
|
375
|
+
}: {
|
|
376
|
+
label: string;
|
|
377
|
+
value: number;
|
|
378
|
+
max: number;
|
|
379
|
+
suffix?: string;
|
|
380
|
+
className?: string;
|
|
381
|
+
onChange: (v: number) => void;
|
|
382
|
+
}) {
|
|
383
|
+
const display = suffix ? `${Math.round(value)}` : `${Math.round(value)}`;
|
|
384
|
+
const [draft, setDraft] = React.useState(display);
|
|
385
|
+
const [focused, setFocused] = React.useState(false);
|
|
386
|
+
|
|
387
|
+
React.useEffect(() => {
|
|
388
|
+
if (!focused) setDraft(display);
|
|
389
|
+
}, [display, focused]);
|
|
390
|
+
|
|
391
|
+
const confirm = () => {
|
|
392
|
+
const n = parseInt(draft, 10);
|
|
393
|
+
if (!isNaN(n)) {
|
|
394
|
+
onChange(Math.min(Math.max(n, 0), max));
|
|
395
|
+
}
|
|
396
|
+
setFocused(false);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
return (
|
|
400
|
+
<div className="flex flex-col items-center gap-0.5">
|
|
401
|
+
<input
|
|
402
|
+
type="text"
|
|
403
|
+
value={focused ? draft : suffix ? `${display}` : display}
|
|
404
|
+
onChange={(e) => setDraft(e.target.value.replace(/[^\d]/g, ''))}
|
|
405
|
+
onFocus={(e) => {
|
|
406
|
+
setFocused(true);
|
|
407
|
+
e.target.select();
|
|
408
|
+
}}
|
|
409
|
+
onBlur={confirm}
|
|
410
|
+
onKeyDown={(e) => e.key === 'Enter' && confirm()}
|
|
411
|
+
className={className}
|
|
412
|
+
/>
|
|
413
|
+
<span className="text-xs text-muted-foreground">{label}</span>
|
|
414
|
+
</div>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function PresetGrid({
|
|
419
|
+
colors,
|
|
420
|
+
currentColor,
|
|
421
|
+
onSelect,
|
|
422
|
+
}: {
|
|
423
|
+
colors: string[];
|
|
424
|
+
currentColor: Color;
|
|
425
|
+
onSelect: (hex: string) => void;
|
|
426
|
+
}) {
|
|
427
|
+
return (
|
|
428
|
+
<div data-slot="color-picker-presets" className="flex flex-wrap gap-1.5">
|
|
429
|
+
{colors.map((hex) => (
|
|
430
|
+
<button
|
|
431
|
+
key={hex}
|
|
432
|
+
type="button"
|
|
433
|
+
onClick={() => onSelect(hex)}
|
|
434
|
+
className={cn(
|
|
435
|
+
'size-5 cursor-pointer rounded-sm border border-border transition-transform hover:scale-110 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
|
436
|
+
currentColor.toHex() === new Color(hex).toHex() &&
|
|
437
|
+
'ring-1 ring-ring ring-offset-1',
|
|
438
|
+
)}
|
|
439
|
+
style={{ backgroundColor: hex }}
|
|
440
|
+
aria-label={hex}
|
|
441
|
+
/>
|
|
442
|
+
))}
|
|
443
|
+
</div>
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// ─── ColorPicker ───────────────────────────────────────────────────────────
|
|
448
|
+
|
|
449
|
+
function ColorPicker({
|
|
450
|
+
value: controlledValue,
|
|
451
|
+
defaultValue = '#1677ff',
|
|
452
|
+
format: controlledFormat,
|
|
453
|
+
defaultFormat = 'hex',
|
|
454
|
+
onFormatChange,
|
|
455
|
+
presets,
|
|
456
|
+
disabled = false,
|
|
457
|
+
onChange,
|
|
458
|
+
onChangeComplete,
|
|
459
|
+
size = 'default',
|
|
460
|
+
showText,
|
|
461
|
+
allowClear = false,
|
|
462
|
+
onClear,
|
|
463
|
+
disabledAlpha = false,
|
|
464
|
+
open: controlledOpen,
|
|
465
|
+
onOpenChange,
|
|
466
|
+
children,
|
|
467
|
+
placement = 'bottom',
|
|
468
|
+
className,
|
|
469
|
+
...props
|
|
470
|
+
}: ColorPickerProps) {
|
|
471
|
+
// ── Color state ──
|
|
472
|
+
const isColorControlled = controlledValue !== undefined;
|
|
473
|
+
const [internalColor, setInternalColor] = React.useState<Color>(() =>
|
|
474
|
+
toColor(defaultValue, '#1677ff'),
|
|
475
|
+
);
|
|
476
|
+
const currentColor = isColorControlled
|
|
477
|
+
? toColor(controlledValue, '#1677ff')
|
|
478
|
+
: internalColor;
|
|
479
|
+
|
|
480
|
+
// ── Open state ──
|
|
481
|
+
const isOpenControlled = controlledOpen !== undefined;
|
|
482
|
+
const [internalOpen, setInternalOpen] = React.useState(false);
|
|
483
|
+
const currentOpen = isOpenControlled ? controlledOpen : internalOpen;
|
|
484
|
+
|
|
485
|
+
const setOpen = (next: boolean) => {
|
|
486
|
+
if (!isOpenControlled) setInternalOpen(next);
|
|
487
|
+
onOpenChange?.(next);
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
// ── Format state ──
|
|
491
|
+
const isFormatControlled = controlledFormat !== undefined;
|
|
492
|
+
const [internalFormat, setInternalFormat] =
|
|
493
|
+
React.useState<ColorFormat>(defaultFormat);
|
|
494
|
+
const currentFormat = isFormatControlled ? controlledFormat : internalFormat;
|
|
495
|
+
|
|
496
|
+
const cycleFormat = () => {
|
|
497
|
+
const idx = FORMAT_CYCLE.indexOf(currentFormat);
|
|
498
|
+
const next = FORMAT_CYCLE[(idx + 1) % FORMAT_CYCLE.length]!;
|
|
499
|
+
if (!isFormatControlled) setInternalFormat(next);
|
|
500
|
+
onFormatChange?.(next);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// ── Change handlers ──
|
|
504
|
+
const handleChange = React.useCallback(
|
|
505
|
+
(c: Color) => {
|
|
506
|
+
const applied = disabledAlpha ? c.setAlpha(1) : c;
|
|
507
|
+
if (!isColorControlled) setInternalColor(applied);
|
|
508
|
+
onChange?.(applied, applied.toHex());
|
|
509
|
+
},
|
|
510
|
+
[isColorControlled, onChange, disabledAlpha],
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const handleChangeComplete = React.useCallback(
|
|
514
|
+
(c: Color) => {
|
|
515
|
+
const applied = disabledAlpha ? c.setAlpha(1) : c;
|
|
516
|
+
onChangeComplete?.(applied, applied.toHex());
|
|
517
|
+
},
|
|
518
|
+
[onChangeComplete, disabledAlpha],
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
const handlePickerChange = React.useCallback(
|
|
522
|
+
(hsva: HsvaColor) => {
|
|
523
|
+
handleChange(new Color(hsva));
|
|
524
|
+
},
|
|
525
|
+
[handleChange],
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
const handlePickerChangeEnd = React.useCallback(
|
|
529
|
+
(hsva: HsvaColor) => {
|
|
530
|
+
handleChangeComplete(new Color(hsva));
|
|
531
|
+
},
|
|
532
|
+
[handleChangeComplete],
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
// Preset click
|
|
536
|
+
const handlePresetSelect = (hex: string) => {
|
|
537
|
+
const c = new Color(hex);
|
|
538
|
+
handleChange(c);
|
|
539
|
+
handleChangeComplete(c);
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// Clear
|
|
543
|
+
const handleClear = (e: React.MouseEvent) => {
|
|
544
|
+
e.stopPropagation();
|
|
545
|
+
onClear?.();
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// ── showText rendering ──
|
|
549
|
+
const textContent =
|
|
550
|
+
showText === true
|
|
551
|
+
? formatColorText(currentColor, currentFormat)
|
|
552
|
+
: typeof showText === 'function'
|
|
553
|
+
? showText(currentColor)
|
|
554
|
+
: null;
|
|
555
|
+
|
|
556
|
+
// ── Render ──
|
|
557
|
+
const hsva = currentColor.toHsva();
|
|
558
|
+
|
|
559
|
+
return (
|
|
560
|
+
<div
|
|
561
|
+
data-slot="color-picker"
|
|
562
|
+
className={cn('inline-block', className)}
|
|
563
|
+
{...props}
|
|
564
|
+
>
|
|
565
|
+
<Popover open={currentOpen} onOpenChange={setOpen}>
|
|
566
|
+
<PopoverTrigger asChild>
|
|
567
|
+
{children ?? (
|
|
568
|
+
<button
|
|
569
|
+
type="button"
|
|
570
|
+
data-slot="color-picker-trigger"
|
|
571
|
+
data-size={size}
|
|
572
|
+
disabled={disabled}
|
|
573
|
+
className={triggerVariants({ size })}
|
|
574
|
+
>
|
|
575
|
+
<ColorSwatch
|
|
576
|
+
color={currentColor.toRgbString()}
|
|
577
|
+
className={swatchVariants({ size })}
|
|
578
|
+
/>
|
|
579
|
+
{textContent && (
|
|
580
|
+
<span className="text-xs text-foreground">{textContent}</span>
|
|
581
|
+
)}
|
|
582
|
+
{allowClear && (
|
|
583
|
+
<span
|
|
584
|
+
role="button"
|
|
585
|
+
tabIndex={-1}
|
|
586
|
+
onClick={handleClear}
|
|
587
|
+
className="inline-flex shrink-0 cursor-pointer items-center text-muted-foreground transition-colors hover:text-foreground"
|
|
588
|
+
>
|
|
589
|
+
<XIcon className="size-3" />
|
|
590
|
+
</span>
|
|
591
|
+
)}
|
|
592
|
+
</button>
|
|
593
|
+
)}
|
|
594
|
+
</PopoverTrigger>
|
|
595
|
+
|
|
596
|
+
<PopoverContent
|
|
597
|
+
data-slot="color-picker-panel"
|
|
598
|
+
side={placement}
|
|
599
|
+
align="start"
|
|
600
|
+
className="w-68 p-3"
|
|
601
|
+
>
|
|
602
|
+
{/* Color picker panel */}
|
|
603
|
+
<div data-slot="color-picker-canvas">
|
|
604
|
+
<style>{PICKER_STYLE_OVERRIDES}</style>
|
|
605
|
+
<HsvaColorPicker
|
|
606
|
+
color={hsva}
|
|
607
|
+
onChange={handlePickerChange}
|
|
608
|
+
onChangeEnd={handlePickerChangeEnd}
|
|
609
|
+
className={disabledAlpha ? 'color-picker-no-alpha' : undefined}
|
|
610
|
+
/>
|
|
611
|
+
</div>
|
|
612
|
+
|
|
613
|
+
{/* Format inputs */}
|
|
614
|
+
<div className="mt-3 flex items-start gap-2">
|
|
615
|
+
<ColorSwatch
|
|
616
|
+
color={currentColor.toRgbString()}
|
|
617
|
+
className="size-6 shrink-0 rounded-sm border border-border"
|
|
618
|
+
/>
|
|
619
|
+
<div className="min-w-0 flex-1">
|
|
620
|
+
<FormatInputs
|
|
621
|
+
color={currentColor}
|
|
622
|
+
format={currentFormat}
|
|
623
|
+
disabledAlpha={disabledAlpha}
|
|
624
|
+
onColorChange={handleChange}
|
|
625
|
+
onChangeComplete={handleChangeComplete}
|
|
626
|
+
/>
|
|
627
|
+
</div>
|
|
628
|
+
<button
|
|
629
|
+
type="button"
|
|
630
|
+
onClick={cycleFormat}
|
|
631
|
+
className="h-6 shrink-0 cursor-pointer rounded-sm px-1.5 text-xs font-medium uppercase text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
|
|
632
|
+
>
|
|
633
|
+
{currentFormat}
|
|
634
|
+
</button>
|
|
635
|
+
</div>
|
|
636
|
+
|
|
637
|
+
{/* Presets */}
|
|
638
|
+
{presets && presets.length > 0 && (
|
|
639
|
+
<div className="mt-3 border-t border-border pt-3">
|
|
640
|
+
{isPresetGroupArray(presets) ? (
|
|
641
|
+
<div className="flex flex-col gap-2">
|
|
642
|
+
{presets.map((group, i) => (
|
|
643
|
+
<Collapsible
|
|
644
|
+
key={i}
|
|
645
|
+
defaultOpen={group.defaultOpen ?? true}
|
|
646
|
+
>
|
|
647
|
+
<CollapsibleTrigger className="flex w-full cursor-pointer items-center justify-between text-xs text-muted-foreground transition-colors hover:text-foreground [&[data-state=open]>svg]:rotate-180">
|
|
648
|
+
<span>{group.label}</span>
|
|
649
|
+
<ChevronDownIcon className="size-3 transition-transform" />
|
|
650
|
+
</CollapsibleTrigger>
|
|
651
|
+
<CollapsibleContent className="mt-1.5">
|
|
652
|
+
<PresetGrid
|
|
653
|
+
colors={group.colors}
|
|
654
|
+
currentColor={currentColor}
|
|
655
|
+
onSelect={handlePresetSelect}
|
|
656
|
+
/>
|
|
657
|
+
</CollapsibleContent>
|
|
658
|
+
</Collapsible>
|
|
659
|
+
))}
|
|
660
|
+
</div>
|
|
661
|
+
) : (
|
|
662
|
+
<PresetGrid
|
|
663
|
+
colors={presets as string[]}
|
|
664
|
+
currentColor={currentColor}
|
|
665
|
+
onSelect={handlePresetSelect}
|
|
666
|
+
/>
|
|
667
|
+
)}
|
|
668
|
+
</div>
|
|
669
|
+
)}
|
|
670
|
+
</PopoverContent>
|
|
671
|
+
</Popover>
|
|
672
|
+
</div>
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export { ColorPicker, Color };
|
|
677
|
+
export type { ColorPickerProps, ColorFormat, ColorPresetGroup, ColorPresets };
|