@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.
@@ -0,0 +1,138 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/color-picker-field.tsx
23
+ var color_picker_field_exports = {};
24
+ __export(color_picker_field_exports, {
25
+ ColorPickerField: () => ColorPickerField
26
+ });
27
+ module.exports = __toCommonJS(color_picker_field_exports);
28
+ var import_i18n2 = require("@kopexa/i18n");
29
+ var import_shared_utils = require("@kopexa/shared-utils");
30
+ var import_react = require("react");
31
+ var import_react_aria_components = require("react-aria-components");
32
+
33
+ // src/messages.ts
34
+ var import_i18n = require("@kopexa/i18n");
35
+ var messages = (0, import_i18n.defineMessages)({
36
+ label: {
37
+ id: "color-picker.label",
38
+ defaultMessage: "Color"
39
+ },
40
+ hexLabel: {
41
+ id: "color-picker.hex_label",
42
+ defaultMessage: "Hex"
43
+ },
44
+ pickColor: {
45
+ id: "color-picker.pick_color",
46
+ defaultMessage: "Pick a color"
47
+ }
48
+ });
49
+
50
+ // src/color-picker-field.tsx
51
+ var import_jsx_runtime = require("react/jsx-runtime");
52
+ var DEFAULT_PRESETS = [
53
+ "#ef4444",
54
+ "#f97316",
55
+ "#eab308",
56
+ "#22c55e",
57
+ "#14b8a6",
58
+ "#3b82f6",
59
+ "#8b5cf6",
60
+ "#ec4899",
61
+ "#6366f1",
62
+ "#a855f7"
63
+ ];
64
+ function ColorPickerField({
65
+ value,
66
+ defaultValue = "#3b82f6",
67
+ onChange,
68
+ presets = DEFAULT_PRESETS,
69
+ hidePresets = false,
70
+ hideHexInput = false,
71
+ triggerClassName,
72
+ triggerContent,
73
+ isDisabled = false
74
+ }) {
75
+ const intl = (0, import_i18n2.useSafeIntl)();
76
+ const t = {
77
+ hexLabel: intl.formatMessage(messages.hexLabel)
78
+ };
79
+ const safeParseColor = (hex) => {
80
+ try {
81
+ return (0, import_react_aria_components.parseColor)(hex);
82
+ } catch {
83
+ return (0, import_react_aria_components.parseColor)("#3b82f6");
84
+ }
85
+ };
86
+ const [color, setColor] = (0, import_react.useState)(
87
+ () => safeParseColor(value != null ? value : defaultValue)
88
+ );
89
+ const handleChange = (newColor) => {
90
+ setColor(newColor);
91
+ onChange == null ? void 0 : onChange(newColor.toString("hex"));
92
+ };
93
+ const hexValue = color.toString("hex");
94
+ const triggerClasses = (0, import_shared_utils.cn)(
95
+ "flex h-10 items-center gap-2 rounded-md border border-input bg-background px-3 text-sm",
96
+ "hover:bg-accent hover:text-accent-foreground",
97
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
98
+ "disabled:pointer-events-none disabled:opacity-50",
99
+ triggerClassName
100
+ );
101
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorPicker, { value: color, onChange: handleChange, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_aria_components.DialogTrigger, { children: [
102
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.Button, { className: triggerClasses, isDisabled, children: triggerContent != null ? triggerContent : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
103
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorSwatch, { className: "size-5 rounded border" }),
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: hexValue })
105
+ ] }) }),
106
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ import_react_aria_components.Popover,
108
+ {
109
+ placement: "bottom start",
110
+ className: "rounded-lg border border-border bg-popover p-3 shadow-lg",
111
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_aria_components.Dialog, { className: "flex flex-col gap-3 outline-none", children: [
112
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
113
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
+ import_react_aria_components.ColorArea,
115
+ {
116
+ colorSpace: "hsb",
117
+ xChannel: "saturation",
118
+ yChannel: "brightness",
119
+ className: "h-[164px] w-[192px] rounded-t-md rounded-b-none border border-b-0",
120
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorThumb, { className: "z-50 size-5 rounded-full border-2 border-white shadow-md" })
121
+ }
122
+ ),
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorSlider, { colorSpace: "hsb", channel: "hue", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.SliderTrack, { className: "h-7 w-[192px] rounded-t-none rounded-b-md border border-t-0", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorThumb, { className: "top-1/2 size-5 rounded-full border-2 border-white shadow-md" }) }) })
124
+ ] }),
125
+ !hideHexInput && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_aria_components.ColorField, { colorSpace: "hsb", className: "flex flex-col gap-1", children: [
126
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.Label, { className: "text-sm", children: t.hexLabel }),
127
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.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" })
128
+ ] }),
129
+ !hidePresets && presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorSwatchPicker, { className: "grid w-[192px] grid-cols-5 gap-1", children: presets.map((preset) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorSwatchPickerItem, { color: preset, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components.ColorSwatch, { className: "size-8 rounded border" }) }, preset)) })
130
+ ] })
131
+ }
132
+ )
133
+ ] }) });
134
+ }
135
+ // Annotate the CommonJS export names for ESM import in node:
136
+ 0 && (module.exports = {
137
+ ColorPickerField
138
+ });
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ ColorPickerField
5
+ } from "./chunk-GSZMYL3E.mjs";
6
+ import "./chunk-JFALBXTO.mjs";
7
+ export {
8
+ ColorPickerField
9
+ };
@@ -0,0 +1,23 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import * as react_aria_components from 'react-aria-components';
4
+ import { ColorWheelProps as ColorWheelProps$1, ColorPicker as ColorPicker$1, ColorAreaProps, SliderTrackProps, ColorThumbProps, ColorSwatchPickerProps, ColorSwatchPickerItemProps, ColorSwatchProps } from 'react-aria-components';
5
+
6
+ declare const ColorSlider: react.ForwardRefExoticComponent<react_aria_components.ColorSliderProps & react.RefAttributes<HTMLDivElement>>;
7
+ declare const ColorField: react.ForwardRefExoticComponent<react_aria_components.ColorFieldProps & react.RefAttributes<HTMLDivElement>>;
8
+ declare const ColorWheelTrack: react.ForwardRefExoticComponent<react_aria_components.ColorWheelTrackProps & react.RefAttributes<HTMLDivElement>>;
9
+ declare const ColorPicker: typeof ColorPicker$1;
10
+ declare const SliderOutput: (props: react_aria_components.SliderOutputProps & React.RefAttributes<HTMLOutputElement>) => React.ReactElement | null;
11
+ interface ColorWheelProps extends Omit<ColorWheelProps$1, "outerRadius" | "innerRadius"> {
12
+ outerRadius?: number;
13
+ innerRadius?: number;
14
+ }
15
+ declare function ColorWheel({ className, outerRadius, innerRadius, ...props }: ColorWheelProps): react_jsx_runtime.JSX.Element;
16
+ declare function ColorArea({ className, ...props }: ColorAreaProps): react_jsx_runtime.JSX.Element;
17
+ declare function SliderTrack({ className, ...props }: SliderTrackProps): react_jsx_runtime.JSX.Element;
18
+ declare function ColorThumb({ className, ...props }: ColorThumbProps): react_jsx_runtime.JSX.Element;
19
+ declare function ColorSwatchPicker({ className, ...props }: ColorSwatchPickerProps): react_jsx_runtime.JSX.Element;
20
+ declare function ColorSwatchPickerItem({ className, ...props }: ColorSwatchPickerItemProps): react_jsx_runtime.JSX.Element;
21
+ declare function ColorSwatch({ className, ...props }: ColorSwatchProps): react_jsx_runtime.JSX.Element;
22
+
23
+ export { ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ColorSwatchPickerItem, ColorThumb, ColorWheel, type ColorWheelProps, ColorWheelTrack, SliderOutput, SliderTrack };
@@ -0,0 +1,23 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import * as react_aria_components from 'react-aria-components';
4
+ import { ColorWheelProps as ColorWheelProps$1, ColorPicker as ColorPicker$1, ColorAreaProps, SliderTrackProps, ColorThumbProps, ColorSwatchPickerProps, ColorSwatchPickerItemProps, ColorSwatchProps } from 'react-aria-components';
5
+
6
+ declare const ColorSlider: react.ForwardRefExoticComponent<react_aria_components.ColorSliderProps & react.RefAttributes<HTMLDivElement>>;
7
+ declare const ColorField: react.ForwardRefExoticComponent<react_aria_components.ColorFieldProps & react.RefAttributes<HTMLDivElement>>;
8
+ declare const ColorWheelTrack: react.ForwardRefExoticComponent<react_aria_components.ColorWheelTrackProps & react.RefAttributes<HTMLDivElement>>;
9
+ declare const ColorPicker: typeof ColorPicker$1;
10
+ declare const SliderOutput: (props: react_aria_components.SliderOutputProps & React.RefAttributes<HTMLOutputElement>) => React.ReactElement | null;
11
+ interface ColorWheelProps extends Omit<ColorWheelProps$1, "outerRadius" | "innerRadius"> {
12
+ outerRadius?: number;
13
+ innerRadius?: number;
14
+ }
15
+ declare function ColorWheel({ className, outerRadius, innerRadius, ...props }: ColorWheelProps): react_jsx_runtime.JSX.Element;
16
+ declare function ColorArea({ className, ...props }: ColorAreaProps): react_jsx_runtime.JSX.Element;
17
+ declare function SliderTrack({ className, ...props }: SliderTrackProps): react_jsx_runtime.JSX.Element;
18
+ declare function ColorThumb({ className, ...props }: ColorThumbProps): react_jsx_runtime.JSX.Element;
19
+ declare function ColorSwatchPicker({ className, ...props }: ColorSwatchPickerProps): react_jsx_runtime.JSX.Element;
20
+ declare function ColorSwatchPickerItem({ className, ...props }: ColorSwatchPickerItemProps): react_jsx_runtime.JSX.Element;
21
+ declare function ColorSwatch({ className, ...props }: ColorSwatchProps): react_jsx_runtime.JSX.Element;
22
+
23
+ export { ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ColorSwatchPickerItem, ColorThumb, ColorWheel, type ColorWheelProps, ColorWheelTrack, SliderOutput, SliderTrack };
@@ -0,0 +1,172 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/color-picker.tsx
23
+ var color_picker_exports = {};
24
+ __export(color_picker_exports, {
25
+ ColorArea: () => ColorArea,
26
+ ColorField: () => ColorField,
27
+ ColorPicker: () => ColorPicker,
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(color_picker_exports);
39
+ var import_shared_utils = require("@kopexa/shared-utils");
40
+ var import_react_aria_components = require("react-aria-components");
41
+ var import_jsx_runtime = require("react/jsx-runtime");
42
+ var ColorSlider = import_react_aria_components.ColorSlider;
43
+ var ColorField = import_react_aria_components.ColorField;
44
+ var ColorWheelTrack = import_react_aria_components.ColorWheelTrack;
45
+ var ColorPicker = import_react_aria_components.ColorPicker;
46
+ var SliderOutput = import_react_aria_components.SliderOutput;
47
+ function ColorWheel({
48
+ className,
49
+ outerRadius = 100,
50
+ innerRadius = 74,
51
+ ...props
52
+ }) {
53
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
54
+ import_react_aria_components.ColorWheel,
55
+ {
56
+ innerRadius,
57
+ outerRadius,
58
+ className: (0, import_react_aria_components.composeRenderProps)(className, (className2) => (0, import_shared_utils.cn)(className2)),
59
+ ...props
60
+ }
61
+ );
62
+ }
63
+ function ColorArea({ className, ...props }) {
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ import_react_aria_components.ColorArea,
66
+ {
67
+ className: (0, import_react_aria_components.composeRenderProps)(
68
+ className,
69
+ (className2) => (0, import_shared_utils.cn)(
70
+ "size-[192px] shrink-0 rounded-md border border-border shadow-md",
71
+ className2
72
+ )
73
+ ),
74
+ ...props
75
+ }
76
+ );
77
+ }
78
+ function SliderTrack({ className, ...props }) {
79
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
80
+ import_react_aria_components.SliderTrack,
81
+ {
82
+ className: (0, import_react_aria_components.composeRenderProps)(
83
+ className,
84
+ (className2) => (0, import_shared_utils.cn)("h-7 w-[192px] rounded-md border border-border", className2)
85
+ ),
86
+ ...props
87
+ }
88
+ );
89
+ }
90
+ function ColorThumb({ className, ...props }) {
91
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
+ import_react_aria_components.ColorThumb,
93
+ {
94
+ className: (0, import_react_aria_components.composeRenderProps)(
95
+ className,
96
+ (className2) => (0, import_shared_utils.cn)(
97
+ "z-10 box-border size-5 rounded-[50%] border-2 border-white shadow-md",
98
+ /* Focus Visible */
99
+ "data-[focus-visible]:size-6",
100
+ className2
101
+ )
102
+ ),
103
+ ...props
104
+ }
105
+ );
106
+ }
107
+ function ColorSwatchPicker({
108
+ className,
109
+ ...props
110
+ }) {
111
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
+ import_react_aria_components.ColorSwatchPicker,
113
+ {
114
+ className: (0, import_react_aria_components.composeRenderProps)(
115
+ className,
116
+ (className2) => (0, import_shared_utils.cn)("flex flex-wrap gap-2", className2)
117
+ ),
118
+ ...props
119
+ }
120
+ );
121
+ }
122
+ function ColorSwatchPickerItem({
123
+ className,
124
+ ...props
125
+ }) {
126
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
127
+ import_react_aria_components.ColorSwatchPickerItem,
128
+ {
129
+ className: (0, import_react_aria_components.composeRenderProps)(
130
+ className,
131
+ (className2) => (0, import_shared_utils.cn)(
132
+ "size-8 overflow-hidden rounded-md border-2 ring-offset-background transition-colors",
133
+ /* Selected */
134
+ "data-[selected]:border-white",
135
+ /* Disabled */
136
+ "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
137
+ /* Focus Visible */
138
+ "data-[focus-visible]:outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring",
139
+ className2
140
+ )
141
+ ),
142
+ ...props
143
+ }
144
+ );
145
+ }
146
+ function ColorSwatch({ className, ...props }) {
147
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
148
+ import_react_aria_components.ColorSwatch,
149
+ {
150
+ className: (0, import_react_aria_components.composeRenderProps)(
151
+ className,
152
+ (className2) => (0, import_shared_utils.cn)("size-8", className2)
153
+ ),
154
+ ...props
155
+ }
156
+ );
157
+ }
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ ColorArea,
161
+ ColorField,
162
+ ColorPicker,
163
+ ColorSlider,
164
+ ColorSwatch,
165
+ ColorSwatchPicker,
166
+ ColorSwatchPickerItem,
167
+ ColorThumb,
168
+ ColorWheel,
169
+ ColorWheelTrack,
170
+ SliderOutput,
171
+ SliderTrack
172
+ });
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ ColorArea,
5
+ ColorField,
6
+ ColorPicker,
7
+ ColorSlider,
8
+ ColorSwatch,
9
+ ColorSwatchPicker,
10
+ ColorSwatchPickerItem,
11
+ ColorThumb,
12
+ ColorWheel,
13
+ ColorWheelTrack,
14
+ SliderOutput,
15
+ SliderTrack
16
+ } from "./chunk-EA7FR3KG.mjs";
17
+ export {
18
+ ColorArea,
19
+ ColorField,
20
+ ColorPicker,
21
+ ColorSlider,
22
+ ColorSwatch,
23
+ ColorSwatchPicker,
24
+ ColorSwatchPickerItem,
25
+ ColorThumb,
26
+ ColorWheel,
27
+ ColorWheelTrack,
28
+ SliderOutput,
29
+ SliderTrack
30
+ };
@@ -0,0 +1,5 @@
1
+ export { ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ColorSwatchPickerItem, ColorThumb, ColorWheel, ColorWheelProps, ColorWheelTrack, SliderOutput, SliderTrack } from './color-picker.mjs';
2
+ export { ColorPickerField, ColorPickerFieldProps } from './color-picker-field.mjs';
3
+ import 'react/jsx-runtime';
4
+ import 'react';
5
+ import 'react-aria-components';
@@ -0,0 +1,5 @@
1
+ export { ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, ColorSwatchPickerItem, ColorThumb, ColorWheel, ColorWheelProps, ColorWheelTrack, SliderOutput, SliderTrack } from './color-picker.js';
2
+ export { ColorPickerField, ColorPickerFieldProps } from './color-picker-field.js';
3
+ import 'react/jsx-runtime';
4
+ import 'react';
5
+ import 'react-aria-components';