@kopexa/color-picker 0.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,284 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ ColorArea: () => ColorArea,
25
+ ColorField: () => ColorField,
26
+ ColorPicker: () => ColorPicker,
27
+ ColorPickerField: () => ColorPickerField,
28
+ ColorSlider: () => ColorSlider,
29
+ ColorSwatch: () => ColorSwatch,
30
+ ColorSwatchPicker: () => ColorSwatchPicker,
31
+ ColorSwatchPickerItem: () => ColorSwatchPickerItem,
32
+ ColorThumb: () => ColorThumb,
33
+ ColorWheel: () => ColorWheel,
34
+ ColorWheelTrack: () => ColorWheelTrack,
35
+ SliderOutput: () => SliderOutput,
36
+ SliderTrack: () => SliderTrack
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // src/color-picker.tsx
41
+ var import_shared_utils = require("@kopexa/shared-utils");
42
+ var import_react_aria_components = require("react-aria-components");
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var ColorSlider = import_react_aria_components.ColorSlider;
45
+ var ColorField = import_react_aria_components.ColorField;
46
+ var ColorWheelTrack = import_react_aria_components.ColorWheelTrack;
47
+ var ColorPicker = import_react_aria_components.ColorPicker;
48
+ var SliderOutput = import_react_aria_components.SliderOutput;
49
+ function ColorWheel({
50
+ className,
51
+ outerRadius = 100,
52
+ innerRadius = 74,
53
+ ...props
54
+ }) {
55
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
56
+ import_react_aria_components.ColorWheel,
57
+ {
58
+ innerRadius,
59
+ outerRadius,
60
+ className: (0, import_react_aria_components.composeRenderProps)(className, (className2) => (0, import_shared_utils.cn)(className2)),
61
+ ...props
62
+ }
63
+ );
64
+ }
65
+ function ColorArea({ className, ...props }) {
66
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
67
+ import_react_aria_components.ColorArea,
68
+ {
69
+ className: (0, import_react_aria_components.composeRenderProps)(
70
+ className,
71
+ (className2) => (0, import_shared_utils.cn)(
72
+ "size-[192px] shrink-0 rounded-md border border-border shadow-md",
73
+ className2
74
+ )
75
+ ),
76
+ ...props
77
+ }
78
+ );
79
+ }
80
+ function SliderTrack({ className, ...props }) {
81
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
82
+ import_react_aria_components.SliderTrack,
83
+ {
84
+ className: (0, import_react_aria_components.composeRenderProps)(
85
+ className,
86
+ (className2) => (0, import_shared_utils.cn)("h-7 w-[192px] rounded-md border border-border", className2)
87
+ ),
88
+ ...props
89
+ }
90
+ );
91
+ }
92
+ function ColorThumb({ className, ...props }) {
93
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
94
+ import_react_aria_components.ColorThumb,
95
+ {
96
+ className: (0, import_react_aria_components.composeRenderProps)(
97
+ className,
98
+ (className2) => (0, import_shared_utils.cn)(
99
+ "z-10 box-border size-5 rounded-[50%] border-2 border-white shadow-md",
100
+ /* Focus Visible */
101
+ "data-[focus-visible]:size-6",
102
+ className2
103
+ )
104
+ ),
105
+ ...props
106
+ }
107
+ );
108
+ }
109
+ function ColorSwatchPicker({
110
+ className,
111
+ ...props
112
+ }) {
113
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
+ import_react_aria_components.ColorSwatchPicker,
115
+ {
116
+ className: (0, import_react_aria_components.composeRenderProps)(
117
+ className,
118
+ (className2) => (0, import_shared_utils.cn)("flex flex-wrap gap-2", className2)
119
+ ),
120
+ ...props
121
+ }
122
+ );
123
+ }
124
+ function ColorSwatchPickerItem({
125
+ className,
126
+ ...props
127
+ }) {
128
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
+ import_react_aria_components.ColorSwatchPickerItem,
130
+ {
131
+ className: (0, import_react_aria_components.composeRenderProps)(
132
+ className,
133
+ (className2) => (0, import_shared_utils.cn)(
134
+ "size-8 overflow-hidden rounded-md border-2 ring-offset-background transition-colors",
135
+ /* Selected */
136
+ "data-[selected]:border-white",
137
+ /* Disabled */
138
+ "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
139
+ /* Focus Visible */
140
+ "data-[focus-visible]:outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring",
141
+ className2
142
+ )
143
+ ),
144
+ ...props
145
+ }
146
+ );
147
+ }
148
+ function ColorSwatch({ className, ...props }) {
149
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
150
+ import_react_aria_components.ColorSwatch,
151
+ {
152
+ className: (0, import_react_aria_components.composeRenderProps)(
153
+ className,
154
+ (className2) => (0, import_shared_utils.cn)("size-8", className2)
155
+ ),
156
+ ...props
157
+ }
158
+ );
159
+ }
160
+
161
+ // src/color-picker-field.tsx
162
+ var import_i18n2 = require("@kopexa/i18n");
163
+ var import_shared_utils2 = require("@kopexa/shared-utils");
164
+ var import_react = require("react");
165
+ var import_react_aria_components2 = require("react-aria-components");
166
+
167
+ // src/messages.ts
168
+ var import_i18n = require("@kopexa/i18n");
169
+ var messages = (0, import_i18n.defineMessages)({
170
+ label: {
171
+ id: "color-picker.label",
172
+ defaultMessage: "Color"
173
+ },
174
+ hexLabel: {
175
+ id: "color-picker.hex_label",
176
+ defaultMessage: "Hex"
177
+ },
178
+ pickColor: {
179
+ id: "color-picker.pick_color",
180
+ defaultMessage: "Pick a color"
181
+ }
182
+ });
183
+
184
+ // src/color-picker-field.tsx
185
+ var import_jsx_runtime2 = require("react/jsx-runtime");
186
+ var DEFAULT_PRESETS = [
187
+ "#ef4444",
188
+ "#f97316",
189
+ "#eab308",
190
+ "#22c55e",
191
+ "#14b8a6",
192
+ "#3b82f6",
193
+ "#8b5cf6",
194
+ "#ec4899",
195
+ "#6366f1",
196
+ "#a855f7"
197
+ ];
198
+ function ColorPickerField({
199
+ value,
200
+ defaultValue = "#3b82f6",
201
+ onChange,
202
+ presets = DEFAULT_PRESETS,
203
+ hidePresets = false,
204
+ hideHexInput = false,
205
+ triggerClassName,
206
+ triggerContent,
207
+ isDisabled = false
208
+ }) {
209
+ const intl = (0, import_i18n2.useSafeIntl)();
210
+ const t = {
211
+ hexLabel: intl.formatMessage(messages.hexLabel)
212
+ };
213
+ const safeParseColor = (hex) => {
214
+ try {
215
+ return (0, import_react_aria_components2.parseColor)(hex);
216
+ } catch {
217
+ return (0, import_react_aria_components2.parseColor)("#3b82f6");
218
+ }
219
+ };
220
+ const [color, setColor] = (0, import_react.useState)(
221
+ () => safeParseColor(value != null ? value : defaultValue)
222
+ );
223
+ const handleChange = (newColor) => {
224
+ setColor(newColor);
225
+ onChange == null ? void 0 : onChange(newColor.toString("hex"));
226
+ };
227
+ const hexValue = color.toString("hex");
228
+ const triggerClasses = (0, import_shared_utils2.cn)(
229
+ "flex h-10 items-center gap-2 rounded-md border border-input bg-background px-3 text-sm",
230
+ "hover:bg-accent hover:text-accent-foreground",
231
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
232
+ "disabled:pointer-events-none disabled:opacity-50",
233
+ triggerClassName
234
+ );
235
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorPicker, { value: color, onChange: handleChange, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_aria_components2.DialogTrigger, { children: [
236
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.Button, { className: triggerClasses, isDisabled, children: triggerContent != null ? triggerContent : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
237
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorSwatch, { className: "size-5 rounded border" }),
238
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "font-mono", children: hexValue })
239
+ ] }) }),
240
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
241
+ import_react_aria_components2.Popover,
242
+ {
243
+ placement: "bottom start",
244
+ className: "rounded-lg border border-border bg-popover p-3 shadow-lg",
245
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_aria_components2.Dialog, { className: "flex flex-col gap-3 outline-none", children: [
246
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
247
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
248
+ import_react_aria_components2.ColorArea,
249
+ {
250
+ colorSpace: "hsb",
251
+ xChannel: "saturation",
252
+ yChannel: "brightness",
253
+ className: "h-[164px] w-[192px] rounded-t-md rounded-b-none border border-b-0",
254
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorThumb, { className: "z-50 size-5 rounded-full border-2 border-white shadow-md" })
255
+ }
256
+ ),
257
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorSlider, { colorSpace: "hsb", channel: "hue", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.SliderTrack, { className: "h-7 w-[192px] rounded-t-none rounded-b-md border border-t-0", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorThumb, { className: "top-1/2 size-5 rounded-full border-2 border-white shadow-md" }) }) })
258
+ ] }),
259
+ !hideHexInput && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_aria_components2.ColorField, { colorSpace: "hsb", className: "flex flex-col gap-1", children: [
260
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.Label, { className: "text-sm", children: t.hexLabel }),
261
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.Input, { className: "h-9 w-[192px] rounded-md border border-input bg-background px-3 font-mono text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring" })
262
+ ] }),
263
+ !hidePresets && presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorSwatchPicker, { className: "grid w-[192px] grid-cols-5 gap-1", children: presets.map((preset) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorSwatchPickerItem, { color: preset, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_aria_components2.ColorSwatch, { className: "size-8 rounded border" }) }, preset)) })
264
+ ] })
265
+ }
266
+ )
267
+ ] }) });
268
+ }
269
+ // Annotate the CommonJS export names for ESM import in node:
270
+ 0 && (module.exports = {
271
+ ColorArea,
272
+ ColorField,
273
+ ColorPicker,
274
+ ColorPickerField,
275
+ ColorSlider,
276
+ ColorSwatch,
277
+ ColorSwatchPicker,
278
+ ColorSwatchPickerItem,
279
+ ColorThumb,
280
+ ColorWheel,
281
+ ColorWheelTrack,
282
+ SliderOutput,
283
+ SliderTrack
284
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import {
3
+ ColorPickerField
4
+ } from "./chunk-GSZMYL3E.mjs";
5
+ import {
6
+ ColorArea,
7
+ ColorField,
8
+ ColorPicker,
9
+ ColorSlider,
10
+ ColorSwatch,
11
+ ColorSwatchPicker,
12
+ ColorSwatchPickerItem,
13
+ ColorThumb,
14
+ ColorWheel,
15
+ ColorWheelTrack,
16
+ SliderOutput,
17
+ SliderTrack
18
+ } from "./chunk-EA7FR3KG.mjs";
19
+ import "./chunk-JFALBXTO.mjs";
20
+ export {
21
+ ColorArea,
22
+ ColorField,
23
+ ColorPicker,
24
+ ColorPickerField,
25
+ ColorSlider,
26
+ ColorSwatch,
27
+ ColorSwatchPicker,
28
+ ColorSwatchPickerItem,
29
+ ColorThumb,
30
+ ColorWheel,
31
+ ColorWheelTrack,
32
+ SliderOutput,
33
+ SliderTrack
34
+ };
@@ -0,0 +1,16 @@
1
+ declare const messages: {
2
+ label: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ };
6
+ hexLabel: {
7
+ id: string;
8
+ defaultMessage: string;
9
+ };
10
+ pickColor: {
11
+ id: string;
12
+ defaultMessage: string;
13
+ };
14
+ };
15
+
16
+ export { messages };
@@ -0,0 +1,16 @@
1
+ declare const messages: {
2
+ label: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ };
6
+ hexLabel: {
7
+ id: string;
8
+ defaultMessage: string;
9
+ };
10
+ pickColor: {
11
+ id: string;
12
+ defaultMessage: string;
13
+ };
14
+ };
15
+
16
+ export { messages };
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/messages.ts
22
+ var messages_exports = {};
23
+ __export(messages_exports, {
24
+ messages: () => messages
25
+ });
26
+ module.exports = __toCommonJS(messages_exports);
27
+ var import_i18n = require("@kopexa/i18n");
28
+ var messages = (0, import_i18n.defineMessages)({
29
+ label: {
30
+ id: "color-picker.label",
31
+ defaultMessage: "Color"
32
+ },
33
+ hexLabel: {
34
+ id: "color-picker.hex_label",
35
+ defaultMessage: "Hex"
36
+ },
37
+ pickColor: {
38
+ id: "color-picker.pick_color",
39
+ defaultMessage: "Pick a color"
40
+ }
41
+ });
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ messages
45
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ messages
4
+ } from "./chunk-JFALBXTO.mjs";
5
+ export {
6
+ messages
7
+ };
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@kopexa/color-picker",
3
+ "version": "0.0.2",
4
+ "description": "Color picker components for selecting and managing colors.",
5
+ "keywords": [
6
+ "color-picker",
7
+ "color",
8
+ "picker"
9
+ ],
10
+ "author": "Kopexa <hello@kopexa.com>",
11
+ "homepage": "https://kopexa.com",
12
+ "license": "Apache-2.0",
13
+ "main": "dist/index.js",
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/kopexa-grc/sight.git",
24
+ "directory": "packages/components/color-picker"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/kopexa-grc/sight/issues"
28
+ },
29
+ "peerDependencies": {
30
+ "react": ">=19.0.0-rc.0",
31
+ "react-dom": ">=19.0.0-rc.0",
32
+ "@kopexa/theme": "17.22.4"
33
+ },
34
+ "dependencies": {
35
+ "react-aria-components": "^1.7.1",
36
+ "@kopexa/shared-utils": "17.0.43",
37
+ "@kopexa/i18n": "17.7.0"
38
+ },
39
+ "clean-package": "../../../clean-package.config.json",
40
+ "module": "dist/index.mjs",
41
+ "types": "dist/index.d.ts",
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "import": "./dist/index.mjs",
46
+ "require": "./dist/index.js"
47
+ },
48
+ "./package.json": "./package.json"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup src --dts",
52
+ "dev": "pnpm build:fast --watch",
53
+ "clean": "rimraf dist .turbo",
54
+ "typecheck": "tsc --noEmit",
55
+ "build:fast": "tsup src"
56
+ }
57
+ }