@wallarm-org/design-system 0.27.0 → 0.27.1-rc-feature-WDS-96-update-data-input-component.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/components/DateInput/DateInput.js +4 -2
- package/dist/components/DateRangeInput/DateRangeContext/DateRangeProvider.js +5 -2
- package/dist/components/DateRangeInput/DateRangeGroup.js +1 -1
- package/dist/components/DateRangeInput/DateRangeInputInternal.js +31 -15
- package/dist/components/DateRangeInput/DateRangeSegmentGroup.js +3 -11
- package/dist/components/TemporalCore/TemporalSegment.js +2 -2
- package/dist/components/TemporalCore/index.d.ts +1 -0
- package/dist/components/TemporalCore/index.js +2 -1
- package/dist/components/TemporalCore/utils.d.ts +8 -0
- package/dist/components/TemporalCore/utils.js +6 -1
- package/dist/components/TimeInput/TimeInput.js +4 -2
- package/dist/metadata/components.json +2 -2
- package/package.json +1 -1
|
@@ -5,9 +5,11 @@ import { useDateField } from "@react-aria/datepicker";
|
|
|
5
5
|
import { useLocale } from "@react-aria/i18n";
|
|
6
6
|
import { useDateFieldState } from "@react-stately/datepicker";
|
|
7
7
|
import { cn } from "../../utils/cn.js";
|
|
8
|
-
import { useTemporalField } from "../TemporalCore/index.js";
|
|
8
|
+
import { getDefaultTemporalPlaceholder, useTemporalField } from "../TemporalCore/index.js";
|
|
9
9
|
import { DateInputInternal } from "./DateInputInternal.js";
|
|
10
|
-
const DateInput = /*#__PURE__*/ forwardRef(({ icon, value: controlledValue, defaultValue, onChange, error = false, disabled = false, granularity = 'day', placeholder
|
|
10
|
+
const DateInput = /*#__PURE__*/ forwardRef(({ icon, value: controlledValue, defaultValue, onChange, error = false, disabled = false, granularity = 'day', placeholder = getDefaultTemporalPlaceholder({
|
|
11
|
+
granularity
|
|
12
|
+
}), showTimeDropdown, timeStep, hourCycle, className, ...props }, forwardedRef)=>{
|
|
11
13
|
const { locale } = useLocale();
|
|
12
14
|
const ref = useRef(null);
|
|
13
15
|
const finalRef = forwardedRef || ref;
|
|
@@ -3,9 +3,12 @@ import { forwardRef, useCallback, useRef } from "react";
|
|
|
3
3
|
import { CalendarDate } from "@internationalized/date";
|
|
4
4
|
import { useDateRangePicker } from "@react-aria/datepicker";
|
|
5
5
|
import { useDateRangePickerState } from "@react-stately/datepicker";
|
|
6
|
-
import { useTemporalField } from "../../TemporalCore/index.js";
|
|
6
|
+
import { getDefaultTemporalPlaceholder, useTemporalField } from "../../TemporalCore/index.js";
|
|
7
7
|
import { DateRangeContext } from "./context.js";
|
|
8
|
-
const DateRangeProvider = /*#__PURE__*/ forwardRef(({ children, value: controlledValue, defaultValue, onChange, error = false, disabled = false, readOnly = false, granularity = 'day', hourCycle, placeholder
|
|
8
|
+
const DateRangeProvider = /*#__PURE__*/ forwardRef(({ children, value: controlledValue, defaultValue, onChange, error = false, disabled = false, readOnly = false, granularity = 'day', hourCycle, placeholder = getDefaultTemporalPlaceholder({
|
|
9
|
+
granularity,
|
|
10
|
+
isRange: true
|
|
11
|
+
}), showTimeDropdown, timeStep, icon }, forwardedRef)=>{
|
|
9
12
|
const ref = useRef(null);
|
|
10
13
|
const finalRef = forwardedRef || ref;
|
|
11
14
|
const startRef = useRef(null);
|
|
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { cva } from "class-variance-authority";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
import { useDateRangeContext } from "./DateRangeContext/index.js";
|
|
5
|
-
const dateRangeGroupVariants = cva(cn('group/temporal flex-1 h-full flex items-center gap-4', 'focus-within:outline-none', 'data-disabled:opacity-50 data-disabled:cursor-not-allowed'));
|
|
5
|
+
const dateRangeGroupVariants = cva(cn('relative group/temporal flex-1 h-full flex items-center gap-4', 'focus-within:outline-none', 'data-disabled:opacity-50 data-disabled:cursor-not-allowed'));
|
|
6
6
|
const DateRangeGroup = ({ children })=>{
|
|
7
7
|
const context = useDateRangeContext();
|
|
8
8
|
const { groupProps = {}, finalRef, disabled, error } = context ?? {};
|
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useCallback, useState } from "react";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
import { InputGroup, InputGroupAddon } from "../InputGroup/index.js";
|
|
5
|
-
import { TemporalClear } from "../TemporalCore/index.js";
|
|
5
|
+
import { TemporalClear, TemporalPlaceholder } from "../TemporalCore/index.js";
|
|
6
6
|
import { useDateRangeContext } from "./DateRangeContext/index.js";
|
|
7
7
|
import { DateRangeGroup } from "./DateRangeGroup.js";
|
|
8
8
|
import { DateRangeSegmentGroup } from "./DateRangeSegmentGroup.js";
|
|
@@ -11,6 +11,7 @@ const DateRangeInputInternal = ({ icon: IconComponent })=>{
|
|
|
11
11
|
const context = useDateRangeContext();
|
|
12
12
|
const [startHasValue, setStartHasValue] = useState(false);
|
|
13
13
|
const [endHasValue, setEndHasValue] = useState(false);
|
|
14
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
14
15
|
const [clearKey, setClearKey] = useState(0);
|
|
15
16
|
const hasAnyValue = startHasValue || endHasValue;
|
|
16
17
|
const handleClear = useCallback(()=>{
|
|
@@ -20,10 +21,17 @@ const DateRangeInputInternal = ({ icon: IconComponent })=>{
|
|
|
20
21
|
}, [
|
|
21
22
|
context
|
|
22
23
|
]);
|
|
24
|
+
const handleFocusCapture = ()=>setIsFocused(true);
|
|
25
|
+
const handleBlurCapture = (event)=>{
|
|
26
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setIsFocused(false);
|
|
27
|
+
};
|
|
23
28
|
if (!context) return null;
|
|
24
|
-
const { startFieldProps, startRef, endFieldProps, endRef, disabled } = context;
|
|
29
|
+
const { startFieldProps, startRef, endFieldProps, endRef, disabled, placeholder } = context;
|
|
30
|
+
const showPlaceholder = Boolean(placeholder && !hasAnyValue && !isFocused);
|
|
25
31
|
return /*#__PURE__*/ jsx("div", {
|
|
26
32
|
className: cn('**:data-[slot=input]:first:pr-0 **:data-[slot=input]:last:pl-0 min-w-284'),
|
|
33
|
+
onFocusCapture: handleFocusCapture,
|
|
34
|
+
onBlurCapture: handleBlurCapture,
|
|
27
35
|
children: /*#__PURE__*/ jsxs(InputGroup, {
|
|
28
36
|
children: [
|
|
29
37
|
IconComponent && /*#__PURE__*/ jsx(InputGroupAddon, {
|
|
@@ -31,19 +39,27 @@ const DateRangeInputInternal = ({ icon: IconComponent })=>{
|
|
|
31
39
|
}),
|
|
32
40
|
/*#__PURE__*/ jsxs(DateRangeGroup, {
|
|
33
41
|
children: [
|
|
34
|
-
/*#__PURE__*/ jsx(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
showPlaceholder && placeholder && /*#__PURE__*/ jsx(TemporalPlaceholder, {
|
|
43
|
+
text: placeholder
|
|
44
|
+
}),
|
|
45
|
+
/*#__PURE__*/ jsxs("div", {
|
|
46
|
+
className: cn('contents', showPlaceholder && '[&>*]:opacity-0'),
|
|
47
|
+
children: [
|
|
48
|
+
/*#__PURE__*/ jsx(DateRangeSegmentGroup, {
|
|
49
|
+
...startFieldProps,
|
|
50
|
+
ref: startRef,
|
|
51
|
+
type: "start",
|
|
52
|
+
onHasPartialValueChange: setStartHasValue
|
|
53
|
+
}, `start-${clearKey}`),
|
|
54
|
+
/*#__PURE__*/ jsx(DateRangeSeparator, {}),
|
|
55
|
+
/*#__PURE__*/ jsx(DateRangeSegmentGroup, {
|
|
56
|
+
...endFieldProps,
|
|
57
|
+
ref: endRef,
|
|
58
|
+
type: "end",
|
|
59
|
+
onHasPartialValueChange: setEndHasValue
|
|
60
|
+
}, `end-${clearKey}`)
|
|
61
|
+
]
|
|
62
|
+
})
|
|
47
63
|
]
|
|
48
64
|
}),
|
|
49
65
|
/*#__PURE__*/ jsx(InputGroupAddon, {
|
|
@@ -5,14 +5,13 @@ import { useDateField } from "@react-aria/datepicker";
|
|
|
5
5
|
import { useLocale } from "@react-aria/i18n";
|
|
6
6
|
import { useDateFieldState } from "@react-stately/datepicker";
|
|
7
7
|
import { cn } from "../../utils/cn.js";
|
|
8
|
-
import {
|
|
8
|
+
import { TemporalSegmentGroup, TimeDropdown, useTimeDropdownKeyCapture } from "../TemporalCore/index.js";
|
|
9
9
|
import { useDateRangeContext } from "./DateRangeContext/index.js";
|
|
10
10
|
const DateRangeSegmentGroup = /*#__PURE__*/ forwardRef(({ type, onHasPartialValueChange, ...props }, ref)=>{
|
|
11
11
|
const context = useDateRangeContext();
|
|
12
|
-
const { disabled = false, error = false, readOnly = false,
|
|
12
|
+
const { disabled = false, error = false, readOnly = false, showTimeDropdown, timeStep = 30, hourCycle, icon } = context ?? {};
|
|
13
13
|
const { locale } = useLocale();
|
|
14
14
|
const dropdownRef = useRef(null);
|
|
15
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
16
15
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
17
16
|
const blurTimeoutRef = useRef(null);
|
|
18
17
|
const fieldState = useDateFieldState({
|
|
@@ -24,7 +23,6 @@ const DateRangeSegmentGroup = /*#__PURE__*/ forwardRef(({ type, onHasPartialValu
|
|
|
24
23
|
});
|
|
25
24
|
const { fieldProps } = useDateField(props, fieldState, ref);
|
|
26
25
|
const hasPartialValue = fieldState.segments.some((seg)=>seg.isEditable && !seg.isPlaceholder);
|
|
27
|
-
const showPlaceholder = placeholder && !hasPartialValue && !isFocused;
|
|
28
26
|
useEffect(()=>{
|
|
29
27
|
onHasPartialValueChange?.(hasPartialValue);
|
|
30
28
|
}, [
|
|
@@ -34,7 +32,6 @@ const DateRangeSegmentGroup = /*#__PURE__*/ forwardRef(({ type, onHasPartialValu
|
|
|
34
32
|
const hasTimeSegments = fieldState.segments.some((seg)=>'hour' === seg.type || 'minute' === seg.type);
|
|
35
33
|
const hasDateSegments = fieldState.segments.some((seg)=>'year' === seg.type || 'month' === seg.type || 'day' === seg.type);
|
|
36
34
|
const handleFocus = ()=>{
|
|
37
|
-
setIsFocused(true);
|
|
38
35
|
if (blurTimeoutRef.current) {
|
|
39
36
|
clearTimeout(blurTimeoutRef.current);
|
|
40
37
|
blurTimeoutRef.current = null;
|
|
@@ -44,7 +41,6 @@ const DateRangeSegmentGroup = /*#__PURE__*/ forwardRef(({ type, onHasPartialValu
|
|
|
44
41
|
if (showTimeDropdown && hasTimeSegments && !isDropdownOpen) setIsDropdownOpen(true);
|
|
45
42
|
};
|
|
46
43
|
const handleBlur = ()=>{
|
|
47
|
-
setIsFocused(false);
|
|
48
44
|
blurTimeoutRef.current = window.setTimeout(()=>{
|
|
49
45
|
setIsDropdownOpen(false);
|
|
50
46
|
}, 200);
|
|
@@ -88,15 +84,11 @@ const DateRangeSegmentGroup = /*#__PURE__*/ forwardRef(({ type, onHasPartialValu
|
|
|
88
84
|
onKeyDownCapture: handleKeyDownCapture,
|
|
89
85
|
onClick: handleClick,
|
|
90
86
|
children: [
|
|
91
|
-
showPlaceholder && /*#__PURE__*/ jsx(TemporalPlaceholder, {
|
|
92
|
-
text: placeholder,
|
|
93
|
-
className: "overflow-hidden text-ellipsis"
|
|
94
|
-
}),
|
|
95
87
|
/*#__PURE__*/ jsx(TemporalSegmentGroup, {
|
|
96
88
|
...fieldProps,
|
|
97
89
|
ref: ref,
|
|
98
90
|
"data-slot": "input",
|
|
99
|
-
className: cn('h-36'
|
|
91
|
+
className: cn('h-36'),
|
|
100
92
|
"aria-disabled": disabled || void 0,
|
|
101
93
|
"aria-invalid": error || void 0,
|
|
102
94
|
"data-field-type": type,
|
|
@@ -4,14 +4,14 @@ import { useDateSegment } from "@react-aria/datepicker";
|
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { cn } from "../../utils/cn.js";
|
|
6
6
|
import { getMonthSegmentText } from "./utils.js";
|
|
7
|
-
const segmentVariants = cva(cn('relative outline-none text-left', 'font-sans text-sm transition-all', 'focus:bg-
|
|
7
|
+
const segmentVariants = cva(cn('relative outline-none text-left', 'font-sans text-sm transition-all', 'focus:bg-states-primary-pressed', 'focus:outline-none'), {
|
|
8
8
|
variants: {
|
|
9
9
|
isPlaceholder: {
|
|
10
10
|
true: 'text-text-secondary',
|
|
11
11
|
false: 'text-text-primary'
|
|
12
12
|
},
|
|
13
13
|
disabled: {
|
|
14
|
-
true: 'cursor-not-allowed
|
|
14
|
+
true: 'cursor-not-allowed',
|
|
15
15
|
false: 'hover:bg-states-primary-default-alt cursor-text'
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
@@ -5,3 +5,4 @@ export { TemporalSegmentGroup } from './TemporalSegmentGroup';
|
|
|
5
5
|
export { TimeDropdown, type TimeDropdownHandle } from './TimeDropdown';
|
|
6
6
|
export { useTemporalField } from './useTemporalField';
|
|
7
7
|
export { useTimeDropdownKeyCapture } from './useTimeDropdownKeyCapture';
|
|
8
|
+
export { getDefaultTemporalPlaceholder, type TemporalGranularity } from './utils';
|
|
@@ -5,4 +5,5 @@ import { TemporalSegmentGroup } from "./TemporalSegmentGroup.js";
|
|
|
5
5
|
import { TimeDropdown } from "./TimeDropdown.js";
|
|
6
6
|
import { useTemporalField } from "./useTemporalField.js";
|
|
7
7
|
import { useTimeDropdownKeyCapture } from "./useTimeDropdownKeyCapture.js";
|
|
8
|
-
|
|
8
|
+
import { getDefaultTemporalPlaceholder } from "./utils.js";
|
|
9
|
+
export { TemporalClear, TemporalPlaceholder, TemporalSegment, TemporalSegmentGroup, TimeDropdown, getDefaultTemporalPlaceholder, useTemporalField, useTimeDropdownKeyCapture };
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export declare function getMonthName(monthNumber: number): string;
|
|
2
2
|
export declare function getMonthSegmentText(value: number | null, placeholder?: string): string;
|
|
3
|
+
export type TemporalGranularity = 'day' | 'hour' | 'minute' | 'second';
|
|
4
|
+
interface DefaultPlaceholderOptions {
|
|
5
|
+
granularity?: TemporalGranularity;
|
|
6
|
+
isRange?: boolean;
|
|
7
|
+
isTimeOnly?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function getDefaultTemporalPlaceholder({ granularity, isRange, isTimeOnly, }: DefaultPlaceholderOptions): string;
|
|
10
|
+
export {};
|
|
@@ -8,4 +8,9 @@ function getMonthSegmentText(value, placeholder = 'MM') {
|
|
|
8
8
|
if (null == value) return placeholder;
|
|
9
9
|
return getMonthName(value);
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
function getDefaultTemporalPlaceholder({ granularity, isRange = false, isTimeOnly = false }) {
|
|
12
|
+
if (isTimeOnly) return 'Select time';
|
|
13
|
+
if ('day' === granularity || void 0 === granularity) return isRange ? 'Select a date range' : 'Select a date';
|
|
14
|
+
return isRange ? 'Select date and time range' : 'Select date and time';
|
|
15
|
+
}
|
|
16
|
+
export { getDefaultTemporalPlaceholder, getMonthName, getMonthSegmentText };
|
|
@@ -4,8 +4,10 @@ import { useTimeField } from "@react-aria/datepicker";
|
|
|
4
4
|
import { useLocale } from "@react-aria/i18n";
|
|
5
5
|
import { useTimeFieldState } from "@react-stately/datepicker";
|
|
6
6
|
import { DateInputInternal } from "../DateInput/index.js";
|
|
7
|
-
import { useTemporalField } from "../TemporalCore/index.js";
|
|
8
|
-
const TimeInput = /*#__PURE__*/ forwardRef(({ icon, value: controlledValue, defaultValue, onChange, error = false, disabled = false, granularity = 'minute', placeholder
|
|
7
|
+
import { getDefaultTemporalPlaceholder, useTemporalField } from "../TemporalCore/index.js";
|
|
8
|
+
const TimeInput = /*#__PURE__*/ forwardRef(({ icon, value: controlledValue, defaultValue, onChange, error = false, disabled = false, granularity = 'minute', placeholder = getDefaultTemporalPlaceholder({
|
|
9
|
+
isTimeOnly: true
|
|
10
|
+
}), showTimeDropdown, timeStep, hourCycle, ...props }, forwardedRef)=>{
|
|
9
11
|
const { locale } = useLocale();
|
|
10
12
|
const ref = useRef(null);
|
|
11
13
|
const finalRef = forwardedRef || ref;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wallarm-org/design-system",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.1-rc-feature-WDS-96-update-data-input-component.2",
|
|
4
4
|
"description": "Core design system library with React components and Storybook documentation",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|