@raystack/apsara 0.49.0 → 0.49.1
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/components/calendar/range-picker.cjs +19 -18
- package/dist/components/calendar/range-picker.cjs.map +1 -1
- package/dist/components/calendar/range-picker.d.ts +5 -4
- package/dist/components/calendar/range-picker.d.ts.map +1 -1
- package/dist/components/calendar/range-picker.js +19 -18
- package/dist/components/calendar/range-picker.js.map +1 -1
- package/dist/components/color-picker/color-picker-alpha.cjs +15 -0
- package/dist/components/color-picker/color-picker-alpha.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-alpha.d.ts +5 -0
- package/dist/components/color-picker/color-picker-alpha.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-alpha.js +13 -0
- package/dist/components/color-picker/color-picker-alpha.js.map +1 -0
- package/dist/components/color-picker/color-picker-area.cjs +73 -0
- package/dist/components/color-picker/color-picker-area.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-area.d.ts +4 -0
- package/dist/components/color-picker/color-picker-area.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-area.js +71 -0
- package/dist/components/color-picker/color-picker-area.js.map +1 -0
- package/dist/components/color-picker/color-picker-hue.cjs +15 -0
- package/dist/components/color-picker/color-picker-hue.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-hue.d.ts +5 -0
- package/dist/components/color-picker/color-picker-hue.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-hue.js +13 -0
- package/dist/components/color-picker/color-picker-hue.js.map +1 -0
- package/dist/components/color-picker/color-picker-input.cjs +16 -0
- package/dist/components/color-picker/color-picker-input.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-input.d.ts +4 -0
- package/dist/components/color-picker/color-picker-input.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-input.js +14 -0
- package/dist/components/color-picker/color-picker-input.js.map +1 -0
- package/dist/components/color-picker/color-picker-mode.cjs +16 -0
- package/dist/components/color-picker/color-picker-mode.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-mode.d.ts +8 -0
- package/dist/components/color-picker/color-picker-mode.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-mode.js +14 -0
- package/dist/components/color-picker/color-picker-mode.js.map +1 -0
- package/dist/components/color-picker/color-picker-root.cjs +53 -0
- package/dist/components/color-picker/color-picker-root.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-root.d.ts +25 -0
- package/dist/components/color-picker/color-picker-root.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-root.js +50 -0
- package/dist/components/color-picker/color-picker-root.js.map +1 -0
- package/dist/components/color-picker/color-picker.cjs +19 -0
- package/dist/components/color-picker/color-picker.cjs.map +1 -0
- package/dist/components/color-picker/color-picker.js +17 -0
- package/dist/components/color-picker/color-picker.js.map +1 -0
- package/dist/components/color-picker/color-picker.module.css.cjs +8 -0
- package/dist/components/color-picker/color-picker.module.css.cjs.map +1 -0
- package/dist/components/color-picker/color-picker.module.css.js +4 -0
- package/dist/components/color-picker/color-picker.module.css.js.map +1 -0
- package/dist/components/color-picker/index.d.ts +2 -0
- package/dist/components/color-picker/index.d.ts.map +1 -0
- package/dist/components/color-picker/utils.cjs +18 -0
- package/dist/components/color-picker/utils.cjs.map +1 -0
- package/dist/components/color-picker/utils.d.ts +11 -0
- package/dist/components/color-picker/utils.d.ts.map +1 -0
- package/dist/components/color-picker/utils.js +15 -0
- package/dist/components/color-picker/utils.js.map +1 -0
- package/dist/components/filter-chip/filter-chip.cjs +1 -1
- package/dist/components/filter-chip/filter-chip.js +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.cjs +986 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.js +982 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.js.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.cjs +86 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.js +82 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.cjs +103 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.js +99 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.js.map +1 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.cjs +157 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.js +153 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.cjs +235 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.js +231 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.cjs +501 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.js +497 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.js.map +1 -0
- package/dist/style.css +1 -1
- package/package.json +2 -1
|
@@ -5,26 +5,27 @@ var reactIcons_esm = require('../../node_modules/.pnpm/@radix-ui_react-icons@1.3
|
|
|
5
5
|
var dayjs_min = require('../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.cjs');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var flex = require('../flex/flex.cjs');
|
|
8
|
+
var inputField = require('../input-field/input-field.cjs');
|
|
8
9
|
var popover = require('../popover/popover.cjs');
|
|
9
10
|
var calendar = require('./calendar.cjs');
|
|
10
11
|
var calendar_module = require('./calendar.module.css.cjs');
|
|
11
|
-
var inputField = require('../input-field/input-field.cjs');
|
|
12
12
|
|
|
13
|
-
function RangePicker({ side =
|
|
13
|
+
function RangePicker({ side = 'top', dateFormat = 'DD/MM/YYYY', inputFieldsProps = {}, calendarProps, onSelect = () => { }, value, defaultValue = {
|
|
14
14
|
to: new Date(),
|
|
15
|
-
from: new Date()
|
|
16
|
-
}, pickerGroupClassName, children, showCalendarIcon = true, footer, timeZone
|
|
15
|
+
from: new Date()
|
|
16
|
+
}, pickerGroupClassName, children, showCalendarIcon = true, footer, timeZone }) {
|
|
17
17
|
const [showCalendar, setShowCalendar] = React.useState(false);
|
|
18
|
-
const [currentRangeField, setCurrentRangeField] = React.useState(
|
|
19
|
-
const [
|
|
20
|
-
const [currentMonth, setCurrentMonth] = React.useState(
|
|
18
|
+
const [currentRangeField, setCurrentRangeField] = React.useState('from');
|
|
19
|
+
const [internalValue, setInternalValue] = React.useState(value ?? defaultValue);
|
|
20
|
+
const [currentMonth, setCurrentMonth] = React.useState(internalValue?.from);
|
|
21
|
+
const selectedRange = value ?? internalValue;
|
|
21
22
|
const prevSelectedRangeRef = React.useRef(selectedRange);
|
|
22
23
|
const startDate = selectedRange.from
|
|
23
24
|
? dayjs_min.default(selectedRange.from).format(dateFormat)
|
|
24
|
-
:
|
|
25
|
+
: '';
|
|
25
26
|
const endDate = selectedRange.to
|
|
26
27
|
? dayjs_min.default(selectedRange.to).format(dateFormat)
|
|
27
|
-
:
|
|
28
|
+
: '';
|
|
28
29
|
// Ensures two months are visible even when
|
|
29
30
|
// current month is the last allowed month (endMonth).
|
|
30
31
|
const computedDefaultMonth = React.useMemo(() => {
|
|
@@ -44,10 +45,10 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
44
45
|
const handleSelect = (range, selectedDay) => {
|
|
45
46
|
// TODO: Remove custom logic and reuse the default logic from react-day-picker
|
|
46
47
|
let newRange;
|
|
47
|
-
if (currentRangeField ===
|
|
48
|
+
if (currentRangeField === 'from') {
|
|
48
49
|
// First click - set from date and prepare for to date selection
|
|
49
50
|
newRange = { from: selectedDay };
|
|
50
|
-
setCurrentRangeField(
|
|
51
|
+
setCurrentRangeField('to');
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
54
|
// Second click - setting to date
|
|
@@ -55,15 +56,15 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
55
56
|
if (dayjs_min.default(selectedDay).isBefore(dayjs_min.default(from))) {
|
|
56
57
|
// If selected date is before current from date, start new range
|
|
57
58
|
newRange = { from: selectedDay };
|
|
58
|
-
setCurrentRangeField(
|
|
59
|
+
setCurrentRangeField('to');
|
|
59
60
|
}
|
|
60
61
|
else {
|
|
61
62
|
// Set the to date
|
|
62
63
|
newRange = { from, to: selectedDay };
|
|
63
|
-
setCurrentRangeField(
|
|
64
|
+
setCurrentRangeField('from');
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
setInternalValue(newRange);
|
|
67
68
|
onSelect(newRange);
|
|
68
69
|
};
|
|
69
70
|
function onOpenChange(open) {
|
|
@@ -71,7 +72,7 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
71
72
|
setShowCalendar(currOpen);
|
|
72
73
|
// Reset selected range if calendar is closed and start or end date is empty
|
|
73
74
|
if (!currOpen && (!startDate.length || !endDate.length)) {
|
|
74
|
-
|
|
75
|
+
setInternalValue(prevSelectedRangeRef.current);
|
|
75
76
|
onSelect(prevSelectedRangeRef.current);
|
|
76
77
|
}
|
|
77
78
|
// Update previous selected range reference when both start and end dates are selected
|
|
@@ -79,11 +80,11 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
79
80
|
prevSelectedRangeRef.current = selectedRange;
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
const defaultTrigger = (jsxRuntime.jsxRuntimeExports.jsxs(flex.Flex, { gap:
|
|
83
|
-
const trigger = typeof children ===
|
|
83
|
+
const defaultTrigger = (jsxRuntime.jsxRuntimeExports.jsxs(flex.Flex, { gap: 'medium', className: pickerGroupClassName, children: [jsxRuntime.jsxRuntimeExports.jsx(inputField.InputField, { size: 'small', placeholder: 'Select start date', trailingIcon: showCalendarIcon ? jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.CalendarIcon, {}) : undefined, className: calendar_module.default.datePickerInput, ...(inputFieldsProps.startDate ?? {}), value: startDate, readOnly: true }), jsxRuntime.jsxRuntimeExports.jsx(inputField.InputField, { size: 'small', placeholder: 'Select end date', trailingIcon: showCalendarIcon ? jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.CalendarIcon, {}) : undefined, className: calendar_module.default.datePickerInput, ...(inputFieldsProps.endDate ?? {}), value: endDate, readOnly: true })] }));
|
|
84
|
+
const trigger = typeof children === 'function'
|
|
84
85
|
? children({ startDate, endDate })
|
|
85
86
|
: children || defaultTrigger;
|
|
86
|
-
return (jsxRuntime.jsxRuntimeExports.jsxs(popover.Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntime.jsxRuntimeExports.jsx(popover.Popover.Trigger, { asChild: true, children: trigger }), jsxRuntime.jsxRuntimeExports.jsxs(popover.Popover.Content, { side: side, className: calendar_module.default.calendarPopover, children: [jsxRuntime.jsxRuntimeExports.jsx(calendar.Calendar, { showOutsideDays: false, numberOfMonths: 2, defaultMonth: selectedRange.from, required: true, ...calendarProps, timeZone: timeZone, mode:
|
|
87
|
+
return (jsxRuntime.jsxRuntimeExports.jsxs(popover.Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntime.jsxRuntimeExports.jsx(popover.Popover.Trigger, { asChild: true, children: trigger }), jsxRuntime.jsxRuntimeExports.jsxs(popover.Popover.Content, { side: side, className: calendar_module.default.calendarPopover, children: [jsxRuntime.jsxRuntimeExports.jsx(calendar.Calendar, { showOutsideDays: false, numberOfMonths: 2, defaultMonth: selectedRange.from, required: true, ...calendarProps, timeZone: timeZone, mode: 'range', month: computedDefaultMonth, selected: selectedRange, onSelect: handleSelect, onMonthChange: setCurrentMonth }), footer && (jsxRuntime.jsxRuntimeExports.jsx(flex.Flex, { align: 'center', justify: 'center', className: calendar_module.default.calendarFooter, children: footer }))] })] }));
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
exports.RangePicker = RangePicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-picker.cjs","sources":["../../../components/calendar/range-picker.tsx"],"sourcesContent":["import { CalendarIcon } from \"@radix-ui/react-icons\";\nimport dayjs from \"dayjs\";\nimport { useRef, useState, useMemo } from \"react\";\nimport { DateRange, PropsBase, PropsRangeRequired } from \"react-day-picker\";\n\nimport { Flex } from \"../flex\";\nimport { Popover } from \"../popover\";\nimport { Calendar } from \"./calendar\";\nimport styles from \"./calendar.module.css\";\nimport { InputField } from \"../input-field\";\nimport { InputFieldProps } from \"../input-field/input-field\";\n\ninterface RangePickerProps {\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n dateFormat?: string;\n inputFieldsProps?: { startDate?: InputFieldProps; endDate?: InputFieldProps };\n calendarProps?: PropsRangeRequired & PropsBase;\n onSelect?: (date: DateRange) => void;\n pickerGroupClassName?: string;\n value?: DateRange;\n children?:\n | React.ReactNode\n | ((props: { startDate: string; endDate: string }) => React.ReactNode);\n showCalendarIcon?: boolean;\n footer?: React.ReactNode;\n timeZone?: string;\n}\n\ntype RangeFields = keyof DateRange;\n\nexport function RangePicker({\n side = \"top\",\n dateFormat = \"DD/MM/YYYY\",\n inputFieldsProps = {},\n calendarProps,\n onSelect = () => {},\n value = {\n to: new Date(),\n from: new Date(),\n },\n pickerGroupClassName,\n children,\n showCalendarIcon = true,\n footer,\n timeZone,\n}: RangePickerProps) {\n const [showCalendar, setShowCalendar] = useState(false);\n const [currentRangeField, setCurrentRangeField] =\n useState<RangeFields>(\"from\");\n const [selectedRange, setSelectedRange] = useState(value);\n const [currentMonth, setCurrentMonth] = useState(selectedRange?.from);\n\n const prevSelectedRangeRef = useRef(selectedRange);\n\n const startDate = selectedRange.from\n ? dayjs(selectedRange.from).format(dateFormat)\n : \"\";\n const endDate = selectedRange.to\n ? dayjs(selectedRange.to).format(dateFormat)\n : \"\";\n\n // Ensures two months are visible even when\n // current month is the last allowed month (endMonth).\n const computedDefaultMonth = useMemo(() => {\n let month = currentMonth;\n if (calendarProps?.endMonth) {\n const endMonth = dayjs(calendarProps.endMonth);\n const fromMonth = dayjs(currentMonth);\n\n if (fromMonth.isSame(endMonth, 'month')) {\n month = endMonth.subtract(1, 'month').toDate();\n }\n }\n return month;\n }, [currentMonth, calendarProps?.endMonth]);\n\n // 1st click will select the start date.\n // 2nd click will select the end date.\n // 3rd click will select the start date again.\n const handleSelect = (range: DateRange, selectedDay: Date) => {\n // TODO: Remove custom logic and reuse the default logic from react-day-picker\n let newRange: DateRange;\n\n if (currentRangeField === \"from\") {\n // First click - set from date and prepare for to date selection\n newRange = { from: selectedDay };\n setCurrentRangeField(\"to\");\n } else {\n // Second click - setting to date\n const from = selectedRange.from;\n\n if (dayjs(selectedDay).isBefore(dayjs(from))) {\n // If selected date is before current from date, start new range\n newRange = { from: selectedDay };\n setCurrentRangeField(\"to\");\n } else {\n // Set the to date\n newRange = { from, to: selectedDay };\n setCurrentRangeField(\"from\");\n }\n }\n\n setSelectedRange(newRange);\n onSelect(newRange);\n };\n\n function onOpenChange(open?: boolean) {\n const currOpen = Boolean(open);\n\n setShowCalendar(currOpen);\n\n // Reset selected range if calendar is closed and start or end date is empty\n if (!currOpen && (!startDate.length || !endDate.length)) {\n setSelectedRange(prevSelectedRangeRef.current);\n onSelect(prevSelectedRangeRef.current);\n }\n\n // Update previous selected range reference when both start and end dates are selected\n if (!currOpen && startDate.length && endDate.length) {\n prevSelectedRangeRef.current = selectedRange;\n }\n }\n\n const defaultTrigger = (\n <Flex gap=\"medium\" className={pickerGroupClassName}>\n <InputField\n size='small'\n placeholder=\"Select start date\"\n trailingIcon={showCalendarIcon ? <CalendarIcon /> : undefined}\n className={styles.datePickerInput}\n {...(inputFieldsProps.startDate ?? {})}\n value={startDate}\n readOnly\n />\n\n <InputField\n size='small'\n placeholder=\"Select end date\"\n trailingIcon={showCalendarIcon ? <CalendarIcon /> : undefined}\n className={styles.datePickerInput}\n {...(inputFieldsProps.endDate ?? {})}\n value={endDate}\n readOnly\n />\n </Flex>\n );\n\n const trigger =\n typeof children === \"function\"\n ? children({ startDate, endDate })\n : children || defaultTrigger;\n\n return (\n <Popover open={showCalendar} onOpenChange={onOpenChange}>\n <Popover.Trigger asChild>{trigger}</Popover.Trigger>\n <Popover.Content side={side} className={styles.calendarPopover}>\n <Calendar\n showOutsideDays={false}\n numberOfMonths={2}\n defaultMonth={selectedRange.from}\n required={true}\n {...calendarProps}\n timeZone={timeZone}\n mode=\"range\"\n month={computedDefaultMonth}\n selected={selectedRange}\n onSelect={handleSelect}\n onMonthChange={setCurrentMonth}\n />\n {footer && (\n <Flex\n align=\"center\"\n justify=\"center\"\n className={styles.calendarFooter}\n >\n {footer}\n </Flex>\n )}\n </Popover.Content>\n </Popover>\n );\n}\n"],"names":["useState","useRef","dayjs","useMemo","_jsxs","Flex","_jsx","InputField","CalendarIcon","styles","Popover","Calendar"],"mappings":";;;;;;;;;;;;AA8BM,SAAU,WAAW,CAAC,EAC1B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ClC,UAAE,QAAQ,IAAI,cAAc,CAAC;IAEjC,QACEL,iCAAC,CAAAM,eAAO,EAAC,EAAA,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAA,QAAA,EAAA,CACrDJ,iCAACI,eAAO,CAAC,OAAO,EAAA,EAAC,OAAO,EAAA,IAAA,EAAA,QAAA,EAAE,OAAO,EAAmB,CAAA,EACpDN,iCAAC,CAAAM,eAAO,CAAC,OAAO,IAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAED,uBAAM,CAAC,eAAe,EAC5D,QAAA,EAAA,CAAAH,gCAAA,CAACK,iBAAQ,EAAA,EACP,eAAe,EAAE,KAAK,EACtB,cAAc,EAAE,CAAC,EACjB,YAAY,EAAE,aAAa,CAAC,IAAI,EAChC,QAAQ,EAAE,IAAI,EAAA,GACV,aAAa,EACjB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,EACZ,KAAK,EAAE,oBAAoB,EAC3B,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,eAAe,EAAA,CAC9B,EACD,MAAM,KACLL,gCAAA,CAACD,SAAI,EAAA,EACH,KAAK,EAAC,QAAQ,EACd,OAAO,EAAC,QAAQ,EAChB,SAAS,EAAEI,uBAAM,CAAC,cAAc,EAAA,QAAA,EAE/B,MAAM,EAAA,CACF,CACR,CAAA,EAAA,CACe,CACV,EAAA,CAAA,EACV;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"range-picker.cjs","sources":["../../../components/calendar/range-picker.tsx"],"sourcesContent":["import { CalendarIcon } from '@radix-ui/react-icons';\nimport dayjs from 'dayjs';\nimport { useMemo, useRef, useState } from 'react';\nimport { DateRange, PropsBase, PropsRangeRequired } from 'react-day-picker';\n\nimport { Flex } from '../flex';\nimport { InputField } from '../input-field';\nimport { InputFieldProps } from '../input-field/input-field';\nimport { Popover } from '../popover';\nimport { Calendar } from './calendar';\nimport styles from './calendar.module.css';\n\ninterface RangePickerProps {\n side?: 'top' | 'right' | 'bottom' | 'left';\n dateFormat?: string;\n inputFieldsProps?: { startDate?: InputFieldProps; endDate?: InputFieldProps };\n calendarProps?: PropsRangeRequired & PropsBase;\n onSelect?: (date: DateRange) => void;\n pickerGroupClassName?: string;\n value?: DateRange;\n defaultValue?: DateRange;\n children?:\n | React.ReactNode\n | ((props: { startDate: string; endDate: string }) => React.ReactNode);\n showCalendarIcon?: boolean;\n footer?: React.ReactNode;\n timeZone?: string;\n}\n\ntype RangeFields = keyof DateRange;\n\nexport function RangePicker({\n side = 'top',\n dateFormat = 'DD/MM/YYYY',\n inputFieldsProps = {},\n calendarProps,\n onSelect = () => {},\n value,\n defaultValue = {\n to: new Date(),\n from: new Date()\n },\n pickerGroupClassName,\n children,\n showCalendarIcon = true,\n footer,\n timeZone\n}: RangePickerProps) {\n const [showCalendar, setShowCalendar] = useState(false);\n const [currentRangeField, setCurrentRangeField] =\n useState<RangeFields>('from');\n const [internalValue, setInternalValue] = useState(value ?? defaultValue);\n const [currentMonth, setCurrentMonth] = useState(internalValue?.from);\n\n const selectedRange = value ?? internalValue;\n\n const prevSelectedRangeRef = useRef(selectedRange);\n\n const startDate = selectedRange.from\n ? dayjs(selectedRange.from).format(dateFormat)\n : '';\n const endDate = selectedRange.to\n ? dayjs(selectedRange.to).format(dateFormat)\n : '';\n\n // Ensures two months are visible even when\n // current month is the last allowed month (endMonth).\n const computedDefaultMonth = useMemo(() => {\n let month = currentMonth;\n if (calendarProps?.endMonth) {\n const endMonth = dayjs(calendarProps.endMonth);\n const fromMonth = dayjs(currentMonth);\n\n if (fromMonth.isSame(endMonth, 'month')) {\n month = endMonth.subtract(1, 'month').toDate();\n }\n }\n return month;\n }, [currentMonth, calendarProps?.endMonth]);\n\n // 1st click will select the start date.\n // 2nd click will select the end date.\n // 3rd click will select the start date again.\n const handleSelect = (range: DateRange, selectedDay: Date) => {\n // TODO: Remove custom logic and reuse the default logic from react-day-picker\n let newRange: DateRange;\n\n if (currentRangeField === 'from') {\n // First click - set from date and prepare for to date selection\n newRange = { from: selectedDay };\n setCurrentRangeField('to');\n } else {\n // Second click - setting to date\n const from = selectedRange.from;\n\n if (dayjs(selectedDay).isBefore(dayjs(from))) {\n // If selected date is before current from date, start new range\n newRange = { from: selectedDay };\n setCurrentRangeField('to');\n } else {\n // Set the to date\n newRange = { from, to: selectedDay };\n setCurrentRangeField('from');\n }\n }\n\n setInternalValue(newRange);\n onSelect(newRange);\n };\n\n function onOpenChange(open?: boolean) {\n const currOpen = Boolean(open);\n\n setShowCalendar(currOpen);\n\n // Reset selected range if calendar is closed and start or end date is empty\n if (!currOpen && (!startDate.length || !endDate.length)) {\n setInternalValue(prevSelectedRangeRef.current);\n onSelect(prevSelectedRangeRef.current);\n }\n\n // Update previous selected range reference when both start and end dates are selected\n if (!currOpen && startDate.length && endDate.length) {\n prevSelectedRangeRef.current = selectedRange;\n }\n }\n\n const defaultTrigger = (\n <Flex gap='medium' className={pickerGroupClassName}>\n <InputField\n size='small'\n placeholder='Select start date'\n trailingIcon={showCalendarIcon ? <CalendarIcon /> : undefined}\n className={styles.datePickerInput}\n {...(inputFieldsProps.startDate ?? {})}\n value={startDate}\n readOnly\n />\n\n <InputField\n size='small'\n placeholder='Select end date'\n trailingIcon={showCalendarIcon ? <CalendarIcon /> : undefined}\n className={styles.datePickerInput}\n {...(inputFieldsProps.endDate ?? {})}\n value={endDate}\n readOnly\n />\n </Flex>\n );\n\n const trigger =\n typeof children === 'function'\n ? children({ startDate, endDate })\n : children || defaultTrigger;\n\n return (\n <Popover open={showCalendar} onOpenChange={onOpenChange}>\n <Popover.Trigger asChild>{trigger}</Popover.Trigger>\n <Popover.Content side={side} className={styles.calendarPopover}>\n <Calendar\n showOutsideDays={false}\n numberOfMonths={2}\n defaultMonth={selectedRange.from}\n required={true}\n {...calendarProps}\n timeZone={timeZone}\n mode='range'\n month={computedDefaultMonth}\n selected={selectedRange}\n onSelect={handleSelect}\n onMonthChange={setCurrentMonth}\n />\n {footer && (\n <Flex\n align='center'\n justify='center'\n className={styles.calendarFooter}\n >\n {footer}\n </Flex>\n )}\n </Popover.Content>\n </Popover>\n );\n}\n"],"names":["useState","useRef","dayjs","useMemo","_jsxs","Flex","_jsx","InputField","CalendarIcon","styles","Popover","Calendar"],"mappings":";;;;;;;;;;;;AA+BgB,SAAA,WAAW,CAAC,EAC1B,IAAI,GAAG,KAAK,EACZ,UAAU,GAAG,YAAY,EACzB,gBAAgB,GAAG,EAAE,EACrB,aAAa,EACb,QAAQ,GAAG,MAAO,GAAC,EACnB,KAAK,EACL,YAAY,GAAG;IACb,EAAE,EAAE,IAAI,IAAI,EAAE;IACd,IAAI,EAAE,IAAI,IAAI,EAAE;CACjB,EACD,oBAAoB,EACpB,QAAQ,EACR,gBAAgB,GAAG,IAAI,EACvB,MAAM,EACN,QAAQ,EACS,EAAA;IACjB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAC7CA,cAAQ,CAAc,MAAM,CAAC,CAAC;AAChC,IAAA,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAGA,cAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,CAAC;AAC1E,IAAA,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAEtE,IAAA,MAAM,aAAa,GAAG,KAAK,IAAI,aAAa,CAAC;AAE7C,IAAA,MAAM,oBAAoB,GAAGC,YAAM,CAAC,aAAa,CAAC,CAAC;AAEnD,IAAA,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI;UAChCC,iBAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;UAC5C,EAAE,CAAC;AACP,IAAA,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE;UAC5BA,iBAAK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|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DateRange, PropsBase, PropsRangeRequired } from
|
|
2
|
-
import { InputFieldProps } from
|
|
1
|
+
import { DateRange, PropsBase, PropsRangeRequired } from 'react-day-picker';
|
|
2
|
+
import { InputFieldProps } from '../input-field/input-field';
|
|
3
3
|
interface RangePickerProps {
|
|
4
|
-
side?:
|
|
4
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
5
5
|
dateFormat?: string;
|
|
6
6
|
inputFieldsProps?: {
|
|
7
7
|
startDate?: InputFieldProps;
|
|
@@ -11,6 +11,7 @@ interface RangePickerProps {
|
|
|
11
11
|
onSelect?: (date: DateRange) => void;
|
|
12
12
|
pickerGroupClassName?: string;
|
|
13
13
|
value?: DateRange;
|
|
14
|
+
defaultValue?: DateRange;
|
|
14
15
|
children?: React.ReactNode | ((props: {
|
|
15
16
|
startDate: string;
|
|
16
17
|
endDate: string;
|
|
@@ -19,6 +20,6 @@ interface RangePickerProps {
|
|
|
19
20
|
footer?: React.ReactNode;
|
|
20
21
|
timeZone?: string;
|
|
21
22
|
}
|
|
22
|
-
export declare function RangePicker({ side, dateFormat, inputFieldsProps, calendarProps, onSelect, value, pickerGroupClassName, children, showCalendarIcon, footer, timeZone
|
|
23
|
+
export declare function RangePicker({ side, dateFormat, inputFieldsProps, calendarProps, onSelect, value, defaultValue, pickerGroupClassName, children, showCalendarIcon, footer, timeZone }: RangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
23
24
|
export {};
|
|
24
25
|
//# sourceMappingURL=range-picker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-picker.d.ts","sourceRoot":"","sources":["../../../components/calendar/range-picker.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"range-picker.d.ts","sourceRoot":"","sources":["../../../components/calendar/range-picker.tsx"],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ules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js';
|
|
4
4
|
import { useState, useRef, useMemo } from 'react';
|
|
5
5
|
import { Flex } from '../flex/flex.js';
|
|
6
|
+
import { InputField } from '../input-field/input-field.js';
|
|
6
7
|
import { Popover } from '../popover/popover.js';
|
|
7
8
|
import { Calendar } from './calendar.js';
|
|
8
9
|
import styles from './calendar.module.css.js';
|
|
9
|
-
import { InputField } from '../input-field/input-field.js';
|
|
10
10
|
|
|
11
|
-
function RangePicker({ side =
|
|
11
|
+
function RangePicker({ side = 'top', dateFormat = 'DD/MM/YYYY', inputFieldsProps = {}, calendarProps, onSelect = () => { }, value, defaultValue = {
|
|
12
12
|
to: new Date(),
|
|
13
|
-
from: new Date()
|
|
14
|
-
}, pickerGroupClassName, children, showCalendarIcon = true, footer, timeZone
|
|
13
|
+
from: new Date()
|
|
14
|
+
}, pickerGroupClassName, children, showCalendarIcon = true, footer, timeZone }) {
|
|
15
15
|
const [showCalendar, setShowCalendar] = useState(false);
|
|
16
|
-
const [currentRangeField, setCurrentRangeField] = useState(
|
|
17
|
-
const [
|
|
18
|
-
const [currentMonth, setCurrentMonth] = useState(
|
|
16
|
+
const [currentRangeField, setCurrentRangeField] = useState('from');
|
|
17
|
+
const [internalValue, setInternalValue] = useState(value ?? defaultValue);
|
|
18
|
+
const [currentMonth, setCurrentMonth] = useState(internalValue?.from);
|
|
19
|
+
const selectedRange = value ?? internalValue;
|
|
19
20
|
const prevSelectedRangeRef = useRef(selectedRange);
|
|
20
21
|
const startDate = selectedRange.from
|
|
21
22
|
? dayjs(selectedRange.from).format(dateFormat)
|
|
22
|
-
:
|
|
23
|
+
: '';
|
|
23
24
|
const endDate = selectedRange.to
|
|
24
25
|
? dayjs(selectedRange.to).format(dateFormat)
|
|
25
|
-
:
|
|
26
|
+
: '';
|
|
26
27
|
// Ensures two months are visible even when
|
|
27
28
|
// current month is the last allowed month (endMonth).
|
|
28
29
|
const computedDefaultMonth = useMemo(() => {
|
|
@@ -42,10 +43,10 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
42
43
|
const handleSelect = (range, selectedDay) => {
|
|
43
44
|
// TODO: Remove custom logic and reuse the default logic from react-day-picker
|
|
44
45
|
let newRange;
|
|
45
|
-
if (currentRangeField ===
|
|
46
|
+
if (currentRangeField === 'from') {
|
|
46
47
|
// First click - set from date and prepare for to date selection
|
|
47
48
|
newRange = { from: selectedDay };
|
|
48
|
-
setCurrentRangeField(
|
|
49
|
+
setCurrentRangeField('to');
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
52
|
// Second click - setting to date
|
|
@@ -53,15 +54,15 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
53
54
|
if (dayjs(selectedDay).isBefore(dayjs(from))) {
|
|
54
55
|
// If selected date is before current from date, start new range
|
|
55
56
|
newRange = { from: selectedDay };
|
|
56
|
-
setCurrentRangeField(
|
|
57
|
+
setCurrentRangeField('to');
|
|
57
58
|
}
|
|
58
59
|
else {
|
|
59
60
|
// Set the to date
|
|
60
61
|
newRange = { from, to: selectedDay };
|
|
61
|
-
setCurrentRangeField(
|
|
62
|
+
setCurrentRangeField('from');
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
setInternalValue(newRange);
|
|
65
66
|
onSelect(newRange);
|
|
66
67
|
};
|
|
67
68
|
function onOpenChange(open) {
|
|
@@ -69,7 +70,7 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
69
70
|
setShowCalendar(currOpen);
|
|
70
71
|
// Reset selected range if calendar is closed and start or end date is empty
|
|
71
72
|
if (!currOpen && (!startDate.length || !endDate.length)) {
|
|
72
|
-
|
|
73
|
+
setInternalValue(prevSelectedRangeRef.current);
|
|
73
74
|
onSelect(prevSelectedRangeRef.current);
|
|
74
75
|
}
|
|
75
76
|
// Update previous selected range reference when both start and end dates are selected
|
|
@@ -77,11 +78,11 @@ function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", inputFieldsProps
|
|
|
77
78
|
prevSelectedRangeRef.current = selectedRange;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
const defaultTrigger = (jsxRuntimeExports.jsxs(Flex, { gap:
|
|
81
|
-
const trigger = typeof children ===
|
|
81
|
+
const defaultTrigger = (jsxRuntimeExports.jsxs(Flex, { gap: 'medium', className: pickerGroupClassName, children: [jsxRuntimeExports.jsx(InputField, { size: 'small', placeholder: 'Select start date', trailingIcon: showCalendarIcon ? jsxRuntimeExports.jsx(CalendarIcon, {}) : undefined, className: styles.datePickerInput, ...(inputFieldsProps.startDate ?? {}), value: startDate, readOnly: true }), jsxRuntimeExports.jsx(InputField, { size: 'small', placeholder: 'Select end date', trailingIcon: showCalendarIcon ? jsxRuntimeExports.jsx(CalendarIcon, {}) : undefined, className: styles.datePickerInput, ...(inputFieldsProps.endDate ?? {}), value: endDate, readOnly: true })] }));
|
|
82
|
+
const trigger = typeof children === 'function'
|
|
82
83
|
? children({ startDate, endDate })
|
|
83
84
|
: children || defaultTrigger;
|
|
84
|
-
return (jsxRuntimeExports.jsxs(Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntimeExports.jsx(Popover.Trigger, { asChild: true, children: trigger }), jsxRuntimeExports.jsxs(Popover.Content, { side: side, className: styles.calendarPopover, children: [jsxRuntimeExports.jsx(Calendar, { showOutsideDays: false, numberOfMonths: 2, defaultMonth: selectedRange.from, required: true, ...calendarProps, timeZone: timeZone, mode:
|
|
85
|
+
return (jsxRuntimeExports.jsxs(Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntimeExports.jsx(Popover.Trigger, { asChild: true, children: trigger }), jsxRuntimeExports.jsxs(Popover.Content, { side: side, className: styles.calendarPopover, children: [jsxRuntimeExports.jsx(Calendar, { showOutsideDays: false, numberOfMonths: 2, defaultMonth: selectedRange.from, required: true, ...calendarProps, timeZone: timeZone, mode: 'range', month: computedDefaultMonth, selected: selectedRange, onSelect: handleSelect, onMonthChange: setCurrentMonth }), footer && (jsxRuntimeExports.jsx(Flex, { align: 'center', justify: 'center', className: styles.calendarFooter, children: footer }))] })] }));
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
export { RangePicker };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range-picker.js","sources":["../../../components/calendar/range-picker.tsx"],"sourcesContent":["import { CalendarIcon } from
|
|
1
|
+
{"version":3,"file":"range-picker.js","sources":["../../../components/calendar/range-picker.tsx"],"sourcesContent":["import { CalendarIcon } from '@radix-ui/react-icons';\nimport dayjs from 'dayjs';\nimport { useMemo, useRef, useState } from 'react';\nimport { DateRange, PropsBase, PropsRangeRequired } from 'react-day-picker';\n\nimport { Flex } from '../flex';\nimport { InputField } from '../input-field';\nimport { InputFieldProps } from '../input-field/input-field';\nimport { Popover } from '../popover';\nimport { Calendar } from './calendar';\nimport styles from './calendar.module.css';\n\ninterface RangePickerProps {\n side?: 'top' | 'right' | 'bottom' | 'left';\n dateFormat?: string;\n inputFieldsProps?: { startDate?: InputFieldProps; endDate?: InputFieldProps };\n calendarProps?: PropsRangeRequired & PropsBase;\n onSelect?: (date: DateRange) => void;\n pickerGroupClassName?: string;\n value?: DateRange;\n defaultValue?: DateRange;\n children?:\n | React.ReactNode\n | ((props: { startDate: string; endDate: string }) => React.ReactNode);\n showCalendarIcon?: boolean;\n footer?: React.ReactNode;\n timeZone?: string;\n}\n\ntype RangeFields = keyof DateRange;\n\nexport function RangePicker({\n side = 'top',\n dateFormat = 'DD/MM/YYYY',\n inputFieldsProps = {},\n calendarProps,\n onSelect = () => {},\n value,\n defaultValue = {\n to: new Date(),\n from: new Date()\n },\n pickerGroupClassName,\n children,\n showCalendarIcon = true,\n footer,\n timeZone\n}: RangePickerProps) {\n const [showCalendar, setShowCalendar] = useState(false);\n const [currentRangeField, setCurrentRangeField] =\n useState<RangeFields>('from');\n const [internalValue, setInternalValue] = useState(value ?? defaultValue);\n const [currentMonth, setCurrentMonth] = useState(internalValue?.from);\n\n const selectedRange = value ?? internalValue;\n\n const prevSelectedRangeRef = useRef(selectedRange);\n\n const startDate = selectedRange.from\n ? dayjs(selectedRange.from).format(dateFormat)\n : '';\n const endDate = selectedRange.to\n ? dayjs(selectedRange.to).format(dateFormat)\n : '';\n\n // Ensures two months are visible even when\n // current month is the last allowed month (endMonth).\n const computedDefaultMonth = useMemo(() => {\n let month = currentMonth;\n if (calendarProps?.endMonth) {\n const endMonth = dayjs(calendarProps.endMonth);\n const fromMonth = dayjs(currentMonth);\n\n if (fromMonth.isSame(endMonth, 'month')) {\n month = endMonth.subtract(1, 'month').toDate();\n }\n }\n return month;\n }, [currentMonth, calendarProps?.endMonth]);\n\n // 1st click will select the start date.\n // 2nd click will select the end date.\n // 3rd click will select the start date again.\n const handleSelect = (range: DateRange, selectedDay: Date) => {\n // TODO: Remove custom logic and reuse the default logic from react-day-picker\n let newRange: DateRange;\n\n if (currentRangeField === 'from') {\n // First click - set from date and prepare for to date selection\n newRange = { from: selectedDay };\n setCurrentRangeField('to');\n } else {\n // Second click - setting to date\n const from = selectedRange.from;\n\n if (dayjs(selectedDay).isBefore(dayjs(from))) {\n // If selected date is before current from date, start new range\n newRange = { from: selectedDay };\n setCurrentRangeField('to');\n } else {\n // Set the to date\n newRange = { from, to: selectedDay };\n setCurrentRangeField('from');\n }\n }\n\n setInternalValue(newRange);\n onSelect(newRange);\n };\n\n function onOpenChange(open?: boolean) {\n const currOpen = Boolean(open);\n\n setShowCalendar(currOpen);\n\n // Reset selected range if calendar is closed and start or end date is empty\n if (!currOpen && (!startDate.length || !endDate.length)) {\n setInternalValue(prevSelectedRangeRef.current);\n onSelect(prevSelectedRangeRef.current);\n }\n\n // Update previous selected range reference when both start and end dates are selected\n if (!currOpen && startDate.length && endDate.length) {\n prevSelectedRangeRef.current = selectedRange;\n }\n }\n\n const defaultTrigger = (\n <Flex gap='medium' className={pickerGroupClassName}>\n <InputField\n size='small'\n placeholder='Select start date'\n trailingIcon={showCalendarIcon ? <CalendarIcon /> : undefined}\n className={styles.datePickerInput}\n {...(inputFieldsProps.startDate ?? {})}\n value={startDate}\n readOnly\n />\n\n <InputField\n size='small'\n placeholder='Select end date'\n trailingIcon={showCalendarIcon ? <CalendarIcon /> : undefined}\n className={styles.datePickerInput}\n {...(inputFieldsProps.endDate ?? {})}\n value={endDate}\n readOnly\n />\n </Flex>\n );\n\n const trigger =\n typeof children === 'function'\n ? children({ startDate, endDate })\n : children || defaultTrigger;\n\n return (\n <Popover open={showCalendar} onOpenChange={onOpenChange}>\n <Popover.Trigger asChild>{trigger}</Popover.Trigger>\n <Popover.Content side={side} className={styles.calendarPopover}>\n <Calendar\n showOutsideDays={false}\n numberOfMonths={2}\n defaultMonth={selectedRange.from}\n required={true}\n {...calendarProps}\n timeZone={timeZone}\n mode='range'\n month={computedDefaultMonth}\n selected={selectedRange}\n onSelect={handleSelect}\n onMonthChange={setCurrentMonth}\n />\n {footer && (\n <Flex\n align='center'\n justify='center'\n className={styles.calendarFooter}\n >\n {footer}\n </Flex>\n )}\n </Popover.Content>\n </Popover>\n );\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AA+BgB,SAAA,WAAW,CAAC,EAC1B,IAAI,GAAG,KAAK,EACZ,UAAU,GAAG,YAAY,EACzB,gBAAgB,GAAG,EAAE,EACrB,aAAa,EACb,QAAQ,GAAG,MAAO,GAAC,EACnB,KAAK,EACL,YAAY,GAAG;IACb,EAAE,EAAE,IAAI,IAAI,EAAE;IACd,IAAI,EAAE,IAAI,IAAI,EAAE;CACjB,EACD,oBAAoB,EACpB,QAAQ,EACR,gBAAgB,GAAG,IAAI,EACvB,MAAM,EACN,QAAQ,EACS,EAAA;IACjB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAC7C,QAAQ,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P,eAAe,EAAE,KAAK,EACtB,cAAc,EAAE,CAAC,EACjB,YAAY,EAAE,aAAa,CAAC,IAAI,EAChC,QAAQ,EAAE,IAAI,EAAA,GACV,aAAa,EACjB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,EACZ,KAAK,EAAE,oBAAoB,EAC3B,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,eAAe,EAAA,CAC9B,EACD,MAAM,KACLA,qBAAA,CAAC,IAAI,EAAA,EACH,KAAK,EAAC,QAAQ,EACd,OAAO,EAAC,QAAQ,EAChB,SAAS,EAAE,MAAM,CAAC,cAAc,EAAA,QAAA,EAE/B,MAAM,EAAA,CACF,CACR,CAAA,EAAA,CACe,CACV,EAAA,CAAA,EACV;AACJ;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
|
|
4
|
+
var index$1 = require('../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.cjs');
|
|
5
|
+
var colorPickerRoot = require('./color-picker-root.cjs');
|
|
6
|
+
var colorPicker_module = require('./color-picker.module.css.cjs');
|
|
7
|
+
var index = require('../../node_modules/.pnpm/@radix-ui_react-slider@1.3.5_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-slider/dist/index.cjs');
|
|
8
|
+
|
|
9
|
+
const ColorPickerAlpha = ({ className, ...props }) => {
|
|
10
|
+
const { alpha = 1, setColor } = colorPickerRoot.useColorPicker();
|
|
11
|
+
return (jsxRuntime.jsxRuntimeExports.jsxs(index.Root, { className: index$1.cx(colorPicker_module.default.sliderRoot, className), max: 100, onValueChange: ([alpha]) => setColor({ alpha: alpha / 100 }), step: 1, value: [alpha * 100], ...props, children: [jsxRuntime.jsxRuntimeExports.jsxs(index.Track, { className: index$1.cx(colorPicker_module.default.sliderTrack, colorPicker_module.default.alphaTrack), children: [jsxRuntime.jsxRuntimeExports.jsx("div", { className: colorPicker_module.default.alphaTrackGradient }), jsxRuntime.jsxRuntimeExports.jsx(index.Range, { className: colorPicker_module.default.sliderRange })] }), jsxRuntime.jsxRuntimeExports.jsx(index.Thumb, { className: colorPicker_module.default.sliderThumb })] }));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.ColorPickerAlpha = ColorPickerAlpha;
|
|
15
|
+
//# sourceMappingURL=color-picker-alpha.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-alpha.cjs","sources":["../../../components/color-picker/color-picker-alpha.tsx"],"sourcesContent":["import { cx } from 'class-variance-authority';\nimport { Slider } from 'radix-ui';\nimport { type ComponentProps } from 'react';\nimport { useColorPicker } from './color-picker-root';\nimport styles from './color-picker.module.css';\n\nexport type ColorPickerAlphaProps = ComponentProps<typeof Slider.Root>;\n\nexport const ColorPickerAlpha = ({\n className,\n ...props\n}: ColorPickerAlphaProps) => {\n const { alpha = 1, setColor } = useColorPicker();\n return (\n <Slider.Root\n className={cx(styles.sliderRoot, className)}\n max={100}\n onValueChange={([alpha]) => setColor({ alpha: alpha / 100 })}\n step={1}\n value={[alpha * 100]}\n {...props}\n >\n <Slider.Track className={cx(styles.sliderTrack, styles.alphaTrack)}>\n <div className={styles.alphaTrackGradient} />\n <Slider.Range className={styles.sliderRange} />\n </Slider.Track>\n <Slider.Thumb className={styles.sliderThumb} />\n </Slider.Root>\n );\n};\n"],"names":["useColorPicker","_jsxs","Slider.Root","cx","styles","Slider.Track","_jsx","Slider.Range","Slider.Thumb"],"mappings":";;;;;;;;AAQO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,GAAG,KAAK,EACc,KAAI;IAC1B,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAGA,8BAAc,EAAE,CAAC;IACjD,QACEC,kCAACC,UAAW,EACV,EAAA,SAAS,EAAEC,UAAE,CAACC,0BAAM,CAAC,UAAU,EAAE,SAAS,CAAC,EAC3C,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG,EAAE,CAAC,EAC5D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,CAAC,EAAA,GAChB,KAAK,EAET,QAAA,EAAA,CAAAH,iCAAA,CAACI,WAAY,EAAA,EAAC,SAAS,EAAEF,UAAE,CAACC,0BAAM,CAAC,WAAW,EAAEA,0BAAM,CAAC,UAAU,CAAC,EAChE,QAAA,EAAA,CAAAE,gCAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAEF,0BAAM,CAAC,kBAAkB,EAAI,CAAA,EAC7CE,iCAACC,WAAY,EAAA,EAAC,SAAS,EAAEH,0BAAM,CAAC,WAAW,EAAI,CAAA,CAAA,EAAA,CAClC,EACfE,gCAAA,CAACE,WAAY,EAAC,EAAA,SAAS,EAAEJ,0BAAM,CAAC,WAAW,EAAA,CAAI,CACnC,EAAA,CAAA,EACd;AACJ;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Slider } from 'radix-ui';
|
|
2
|
+
import { type ComponentProps } from 'react';
|
|
3
|
+
export type ColorPickerAlphaProps = ComponentProps<typeof Slider.Root>;
|
|
4
|
+
export declare const ColorPickerAlpha: ({ className, ...props }: ColorPickerAlphaProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
//# sourceMappingURL=color-picker-alpha.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-alpha.d.ts","sourceRoot":"","sources":["../../../components/color-picker/color-picker-alpha.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAI5C,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AAEvE,eAAO,MAAM,gBAAgB,4BAG1B,qBAAqB,4CAkBvB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
|
|
2
|
+
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
|
|
3
|
+
import { useColorPicker } from './color-picker-root.js';
|
|
4
|
+
import styles from './color-picker.module.css.js';
|
|
5
|
+
import { Root, Track, Range, Thumb } from '../../node_modules/.pnpm/@radix-ui_react-slider@1.3.5_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-slider/dist/index.js';
|
|
6
|
+
|
|
7
|
+
const ColorPickerAlpha = ({ className, ...props }) => {
|
|
8
|
+
const { alpha = 1, setColor } = useColorPicker();
|
|
9
|
+
return (jsxRuntimeExports.jsxs(Root, { className: cx(styles.sliderRoot, className), max: 100, onValueChange: ([alpha]) => setColor({ alpha: alpha / 100 }), step: 1, value: [alpha * 100], ...props, children: [jsxRuntimeExports.jsxs(Track, { className: cx(styles.sliderTrack, styles.alphaTrack), children: [jsxRuntimeExports.jsx("div", { className: styles.alphaTrackGradient }), jsxRuntimeExports.jsx(Range, { className: styles.sliderRange })] }), jsxRuntimeExports.jsx(Thumb, { className: styles.sliderThumb })] }));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { ColorPickerAlpha };
|
|
13
|
+
//# sourceMappingURL=color-picker-alpha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-alpha.js","sources":["../../../components/color-picker/color-picker-alpha.tsx"],"sourcesContent":["import { cx } from 'class-variance-authority';\nimport { Slider } from 'radix-ui';\nimport { type ComponentProps } from 'react';\nimport { useColorPicker } from './color-picker-root';\nimport styles from './color-picker.module.css';\n\nexport type ColorPickerAlphaProps = ComponentProps<typeof Slider.Root>;\n\nexport const ColorPickerAlpha = ({\n className,\n ...props\n}: ColorPickerAlphaProps) => {\n const { alpha = 1, setColor } = useColorPicker();\n return (\n <Slider.Root\n className={cx(styles.sliderRoot, className)}\n max={100}\n onValueChange={([alpha]) => setColor({ alpha: alpha / 100 })}\n step={1}\n value={[alpha * 100]}\n {...props}\n >\n <Slider.Track className={cx(styles.sliderTrack, styles.alphaTrack)}>\n <div className={styles.alphaTrackGradient} />\n <Slider.Range className={styles.sliderRange} />\n </Slider.Track>\n <Slider.Thumb className={styles.sliderThumb} />\n </Slider.Root>\n );\n};\n"],"names":["_jsxs","Slider.Root","Slider.Track","_jsx","Slider.Range","Slider.Thumb"],"mappings":";;;;;;AAQO,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,GAAG,KAAK,EACc,KAAI;IAC1B,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,CAAC;IACjD,QACEA,uBAACC,IAAW,EACV,EAAA,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,EAC3C,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG,EAAE,CAAC,EAC5D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,CAAC,EAAA,GAChB,KAAK,EAET,QAAA,EAAA,CAAAD,sBAAA,CAACE,KAAY,EAAA,EAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,EAChE,QAAA,EAAA,CAAAC,qBAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,kBAAkB,EAAI,CAAA,EAC7CA,sBAACC,KAAY,EAAA,EAAC,SAAS,EAAE,MAAM,CAAC,WAAW,EAAI,CAAA,CAAA,EAAA,CAClC,EACfD,qBAAA,CAACE,KAAY,EAAC,EAAA,SAAS,EAAE,MAAM,CAAC,WAAW,EAAA,CAAI,CACnC,EAAA,CAAA,EACd;AACJ;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
|
|
4
|
+
var index$1 = require('../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.cjs');
|
|
5
|
+
var index = require('../../node_modules/.pnpm/color@5.0.0/node_modules/color/index.cjs');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var colorPickerRoot = require('./color-picker-root.cjs');
|
|
8
|
+
var colorPicker_module = require('./color-picker.module.css.cjs');
|
|
9
|
+
|
|
10
|
+
const ColorPickerArea = ({ className, ...props }) => {
|
|
11
|
+
const containerRef = React.useRef(null);
|
|
12
|
+
const thumbRef = React.useRef(null);
|
|
13
|
+
const isDragging = React.useRef(false);
|
|
14
|
+
const isThumbVisible = React.useRef(false);
|
|
15
|
+
const { hue, saturation, lightness, setColor } = colorPickerRoot.useColorPicker();
|
|
16
|
+
const color = index.default.hsl(hue, saturation, lightness);
|
|
17
|
+
const backgroundGradient = React.useMemo(() => {
|
|
18
|
+
return `linear-gradient(0deg, rgba(0,0,0,1), rgba(0,0,0,0)),
|
|
19
|
+
linear-gradient(90deg, rgba(255,255,255,1), rgba(255,255,255,0)),
|
|
20
|
+
hsl(${hue}, 100%, 50%)`;
|
|
21
|
+
}, [hue]);
|
|
22
|
+
// Need to use useEffect as color can change from outside, and we need to sync thumb position
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (!containerRef.current || !thumbRef.current)
|
|
25
|
+
return;
|
|
26
|
+
const clamp = (v) => Math.max(0, Math.min(1, v));
|
|
27
|
+
const x = clamp(saturation / 100);
|
|
28
|
+
const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);
|
|
29
|
+
const y = clamp(1 - lightness / topLightness);
|
|
30
|
+
thumbRef.current.style.left = `${x * 100}%`;
|
|
31
|
+
thumbRef.current.style.top = `${y * 100}%`;
|
|
32
|
+
// This is needed to avoid flickering of the thumb on initial render
|
|
33
|
+
if (!isThumbVisible.current) {
|
|
34
|
+
isThumbVisible.current = true;
|
|
35
|
+
thumbRef.current.style.opacity = '1';
|
|
36
|
+
}
|
|
37
|
+
}, [saturation, lightness]);
|
|
38
|
+
const handlePointerMove = React.useCallback((event) => {
|
|
39
|
+
if (!(isDragging.current && containerRef.current && thumbRef.current)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
event.stopPropagation();
|
|
44
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
45
|
+
const x = Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width));
|
|
46
|
+
const y = Math.max(0, Math.min(1, (event.clientY - rect.top) / rect.height));
|
|
47
|
+
const saturation = x * 100;
|
|
48
|
+
const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);
|
|
49
|
+
const lightness = topLightness * (1 - y);
|
|
50
|
+
setColor({ s: saturation, l: lightness });
|
|
51
|
+
}, [setColor]);
|
|
52
|
+
const handlePointerUp = React.useCallback(() => {
|
|
53
|
+
isDragging.current = false;
|
|
54
|
+
window.removeEventListener('pointermove', handlePointerMove);
|
|
55
|
+
window.removeEventListener('pointerup', handlePointerUp);
|
|
56
|
+
}, [handlePointerMove]);
|
|
57
|
+
const handlePointerDown = React.useCallback((e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
isDragging.current = true;
|
|
60
|
+
handlePointerMove(e.nativeEvent);
|
|
61
|
+
window.addEventListener('pointermove', handlePointerMove);
|
|
62
|
+
window.addEventListener('pointerup', handlePointerUp);
|
|
63
|
+
}, [handlePointerMove, handlePointerUp]);
|
|
64
|
+
return (jsxRuntime.jsxRuntimeExports.jsx("div", { className: index$1.cx(colorPicker_module.default.selectionRoot, className), onPointerDown: handlePointerDown, ref: containerRef, style: {
|
|
65
|
+
background: backgroundGradient
|
|
66
|
+
}, ...props, children: jsxRuntime.jsxRuntimeExports.jsx("div", { className: index$1.cx(colorPicker_module.default.sliderThumb, colorPicker_module.default.selectionThumb), ref: thumbRef, style: {
|
|
67
|
+
background: color.hex().toString(),
|
|
68
|
+
opacity: 0
|
|
69
|
+
} }) }));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
exports.ColorPickerArea = ColorPickerArea;
|
|
73
|
+
//# sourceMappingURL=color-picker-area.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-area.cjs","sources":["../../../components/color-picker/color-picker-area.tsx"],"sourcesContent":["import { cx } from 'class-variance-authority';\nimport Color from 'color';\nimport {\n type HTMLAttributes,\n PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef\n} from 'react';\nimport { useColorPicker } from './color-picker-root';\nimport styles from './color-picker.module.css';\n\nexport type ColorPickerAreaProps = HTMLAttributes<HTMLDivElement>;\n\nexport const ColorPickerArea = ({\n className,\n ...props\n}: ColorPickerAreaProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const thumbRef = useRef<HTMLDivElement>(null);\n const isDragging = useRef(false);\n const isThumbVisible = useRef(false);\n\n const { hue, saturation, lightness, setColor } = useColorPicker();\n const color = Color.hsl(hue, saturation, lightness);\n\n const backgroundGradient = useMemo(() => {\n return `linear-gradient(0deg, rgba(0,0,0,1), rgba(0,0,0,0)),\n linear-gradient(90deg, rgba(255,255,255,1), rgba(255,255,255,0)),\n hsl(${hue}, 100%, 50%)`;\n }, [hue]);\n\n // Need to use useEffect as color can change from outside, and we need to sync thumb position\n useEffect(() => {\n if (!containerRef.current || !thumbRef.current) return;\n\n const clamp = (v: number) => Math.max(0, Math.min(1, v));\n const x = clamp(saturation / 100);\n const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);\n const y = clamp(1 - lightness / topLightness);\n\n thumbRef.current.style.left = `${x * 100}%`;\n thumbRef.current.style.top = `${y * 100}%`;\n\n // This is needed to avoid flickering of the thumb on initial render\n if (!isThumbVisible.current) {\n isThumbVisible.current = true;\n thumbRef.current.style.opacity = '1';\n }\n }, [saturation, lightness]);\n\n const handlePointerMove = useCallback(\n (event: PointerEvent) => {\n if (!(isDragging.current && containerRef.current && thumbRef.current)) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n const rect = containerRef.current.getBoundingClientRect();\n const x = Math.max(\n 0,\n Math.min(1, (event.clientX - rect.left) / rect.width)\n );\n const y = Math.max(\n 0,\n Math.min(1, (event.clientY - rect.top) / rect.height)\n );\n const saturation = x * 100;\n const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);\n const lightness = topLightness * (1 - y);\n setColor({ s: saturation, l: lightness });\n },\n [setColor]\n );\n\n const handlePointerUp = useCallback(() => {\n isDragging.current = false;\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUp);\n }, [handlePointerMove]);\n\n const handlePointerDown = useCallback(\n (e: ReactPointerEvent<HTMLDivElement>) => {\n e.preventDefault();\n isDragging.current = true;\n handlePointerMove(e.nativeEvent);\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerUp);\n },\n [handlePointerMove, handlePointerUp]\n );\n\n return (\n <div\n className={cx(styles.selectionRoot, className)}\n onPointerDown={handlePointerDown}\n ref={containerRef}\n style={{\n background: backgroundGradient\n }}\n {...props}\n >\n <div\n className={cx(styles.sliderThumb, styles.selectionThumb)}\n ref={thumbRef}\n style={{\n background: color.hex().toString(),\n opacity: 0\n }}\n />\n </div>\n );\n};\n"],"names":["useRef","useColorPicker","Color","useMemo","useEffect","useCallback","_jsx","cx","styles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AEC,UAAE,CAACC,0BAAM,CAAC,WAAW,EAAEA,0BAAM,CAAC,cAAc,CAAC,EACxD,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE;AACL,gBAAA,UAAU,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;AAClC,gBAAA,OAAO,EAAE,CAAC;aACX,EACD,CAAA,EAAA,CACE,EACN;AACJ;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
export type ColorPickerAreaProps = HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export declare const ColorPickerArea: ({ className, ...props }: ColorPickerAreaProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
//# sourceMappingURL=color-picker-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-area.d.ts","sourceRoot":"","sources":["../../../components/color-picker/color-picker-area.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EAMpB,MAAM,OAAO,CAAC;AAIf,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;AAElE,eAAO,MAAM,eAAe,4FAkG3B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
|
|
2
|
+
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
|
|
3
|
+
import Color from '../../node_modules/.pnpm/color@5.0.0/node_modules/color/index.js';
|
|
4
|
+
import { useRef, useMemo, useEffect, useCallback } from 'react';
|
|
5
|
+
import { useColorPicker } from './color-picker-root.js';
|
|
6
|
+
import styles from './color-picker.module.css.js';
|
|
7
|
+
|
|
8
|
+
const ColorPickerArea = ({ className, ...props }) => {
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const thumbRef = useRef(null);
|
|
11
|
+
const isDragging = useRef(false);
|
|
12
|
+
const isThumbVisible = useRef(false);
|
|
13
|
+
const { hue, saturation, lightness, setColor } = useColorPicker();
|
|
14
|
+
const color = Color.hsl(hue, saturation, lightness);
|
|
15
|
+
const backgroundGradient = useMemo(() => {
|
|
16
|
+
return `linear-gradient(0deg, rgba(0,0,0,1), rgba(0,0,0,0)),
|
|
17
|
+
linear-gradient(90deg, rgba(255,255,255,1), rgba(255,255,255,0)),
|
|
18
|
+
hsl(${hue}, 100%, 50%)`;
|
|
19
|
+
}, [hue]);
|
|
20
|
+
// Need to use useEffect as color can change from outside, and we need to sync thumb position
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!containerRef.current || !thumbRef.current)
|
|
23
|
+
return;
|
|
24
|
+
const clamp = (v) => Math.max(0, Math.min(1, v));
|
|
25
|
+
const x = clamp(saturation / 100);
|
|
26
|
+
const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);
|
|
27
|
+
const y = clamp(1 - lightness / topLightness);
|
|
28
|
+
thumbRef.current.style.left = `${x * 100}%`;
|
|
29
|
+
thumbRef.current.style.top = `${y * 100}%`;
|
|
30
|
+
// This is needed to avoid flickering of the thumb on initial render
|
|
31
|
+
if (!isThumbVisible.current) {
|
|
32
|
+
isThumbVisible.current = true;
|
|
33
|
+
thumbRef.current.style.opacity = '1';
|
|
34
|
+
}
|
|
35
|
+
}, [saturation, lightness]);
|
|
36
|
+
const handlePointerMove = useCallback((event) => {
|
|
37
|
+
if (!(isDragging.current && containerRef.current && thumbRef.current)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
43
|
+
const x = Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width));
|
|
44
|
+
const y = Math.max(0, Math.min(1, (event.clientY - rect.top) / rect.height));
|
|
45
|
+
const saturation = x * 100;
|
|
46
|
+
const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);
|
|
47
|
+
const lightness = topLightness * (1 - y);
|
|
48
|
+
setColor({ s: saturation, l: lightness });
|
|
49
|
+
}, [setColor]);
|
|
50
|
+
const handlePointerUp = useCallback(() => {
|
|
51
|
+
isDragging.current = false;
|
|
52
|
+
window.removeEventListener('pointermove', handlePointerMove);
|
|
53
|
+
window.removeEventListener('pointerup', handlePointerUp);
|
|
54
|
+
}, [handlePointerMove]);
|
|
55
|
+
const handlePointerDown = useCallback((e) => {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
isDragging.current = true;
|
|
58
|
+
handlePointerMove(e.nativeEvent);
|
|
59
|
+
window.addEventListener('pointermove', handlePointerMove);
|
|
60
|
+
window.addEventListener('pointerup', handlePointerUp);
|
|
61
|
+
}, [handlePointerMove, handlePointerUp]);
|
|
62
|
+
return (jsxRuntimeExports.jsx("div", { className: cx(styles.selectionRoot, className), onPointerDown: handlePointerDown, ref: containerRef, style: {
|
|
63
|
+
background: backgroundGradient
|
|
64
|
+
}, ...props, children: jsxRuntimeExports.jsx("div", { className: cx(styles.sliderThumb, styles.selectionThumb), ref: thumbRef, style: {
|
|
65
|
+
background: color.hex().toString(),
|
|
66
|
+
opacity: 0
|
|
67
|
+
} }) }));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { ColorPickerArea };
|
|
71
|
+
//# sourceMappingURL=color-picker-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-area.js","sources":["../../../components/color-picker/color-picker-area.tsx"],"sourcesContent":["import { cx } from 'class-variance-authority';\nimport Color from 'color';\nimport {\n type HTMLAttributes,\n PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef\n} from 'react';\nimport { useColorPicker } from './color-picker-root';\nimport styles from './color-picker.module.css';\n\nexport type ColorPickerAreaProps = HTMLAttributes<HTMLDivElement>;\n\nexport const ColorPickerArea = ({\n className,\n ...props\n}: ColorPickerAreaProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const thumbRef = useRef<HTMLDivElement>(null);\n const isDragging = useRef(false);\n const isThumbVisible = useRef(false);\n\n const { hue, saturation, lightness, setColor } = useColorPicker();\n const color = Color.hsl(hue, saturation, lightness);\n\n const backgroundGradient = useMemo(() => {\n return `linear-gradient(0deg, rgba(0,0,0,1), rgba(0,0,0,0)),\n linear-gradient(90deg, rgba(255,255,255,1), rgba(255,255,255,0)),\n hsl(${hue}, 100%, 50%)`;\n }, [hue]);\n\n // Need to use useEffect as color can change from outside, and we need to sync thumb position\n useEffect(() => {\n if (!containerRef.current || !thumbRef.current) return;\n\n const clamp = (v: number) => Math.max(0, Math.min(1, v));\n const x = clamp(saturation / 100);\n const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);\n const y = clamp(1 - lightness / topLightness);\n\n thumbRef.current.style.left = `${x * 100}%`;\n thumbRef.current.style.top = `${y * 100}%`;\n\n // This is needed to avoid flickering of the thumb on initial render\n if (!isThumbVisible.current) {\n isThumbVisible.current = true;\n thumbRef.current.style.opacity = '1';\n }\n }, [saturation, lightness]);\n\n const handlePointerMove = useCallback(\n (event: PointerEvent) => {\n if (!(isDragging.current && containerRef.current && thumbRef.current)) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n const rect = containerRef.current.getBoundingClientRect();\n const x = Math.max(\n 0,\n Math.min(1, (event.clientX - rect.left) / rect.width)\n );\n const y = Math.max(\n 0,\n Math.min(1, (event.clientY - rect.top) / rect.height)\n );\n const saturation = x * 100;\n const topLightness = x < 0.01 ? 100 : 50 + 50 * (1 - x);\n const lightness = topLightness * (1 - y);\n setColor({ s: saturation, l: lightness });\n },\n [setColor]\n );\n\n const handlePointerUp = useCallback(() => {\n isDragging.current = false;\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerUp);\n }, [handlePointerMove]);\n\n const handlePointerDown = useCallback(\n (e: ReactPointerEvent<HTMLDivElement>) => {\n e.preventDefault();\n isDragging.current = true;\n handlePointerMove(e.nativeEvent);\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerUp);\n },\n [handlePointerMove, handlePointerUp]\n );\n\n return (\n <div\n className={cx(styles.selectionRoot, className)}\n onPointerDown={handlePointerDown}\n ref={containerRef}\n style={{\n background: backgroundGradient\n }}\n {...props}\n >\n <div\n className={cx(styles.sliderThumb, styles.selectionThumb)}\n ref={thumbRef}\n style={{\n background: color.hex().toString(),\n opacity: 0\n }}\n />\n </div>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;AAeO,MAAM,eAAe,GAAG,CAAC,EAC9B,SAAS,EACT,GAAG,KAAK,EACa,KAAI;AACzB,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;AAClD,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;AAC9C,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAErC,IAAA,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,CAAC;AAClE,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAEpD,IAAA,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAK;QACtC,OAAO,CAAA;;AAEO,gBAAA,EAAA,GAAG,cAAc,CAAC;AAClC,KAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;;IAGV,SAAS,CAAC,MAAK;QACb,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO;YAAE,OAAO;QAEvD,MAAM,KAAK,GAAG,CAAC,CAAS,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CA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