@react-fabric/superdate 1.0.0-beta.62 → 1.0.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.
@@ -21,35 +21,22 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
+ /* eslint-disable @eslint-react/set-state-in-effect */
25
+
24
26
  import { useFloatingTree } from "@floating-ui/react";
25
- import {
26
- Button,
27
- Chip,
28
- Content,
29
- Dropdown,
30
- Tab,
31
- TabPanel,
32
- Tooltip,
33
- useGlobals,
34
- } from "@react-fabric/core";
27
+ import { Button, Chip, Dropdown, Tab, TabPanel, Tooltip, useApplicationContext } from "@react-fabric/core";
35
28
  import { DateUtil, EventPanel, RangePanel } from "@react-fabric/date";
36
- import classNames from "classnames";
29
+ import { cn } from "@react-fabric/utilities";
37
30
  import { useCallback, useEffect, useMemo, useState } from "react";
38
31
  import { useTranslation } from "react-i18next";
39
32
  import { type SuperDateProps } from "../types";
40
33
  import { QuickSelect } from "./QuickSelect";
41
34
  import { RelativePanel } from "./RelativePanel";
42
35
 
43
- export const SuperDateTabs = ({
44
- events,
45
- value,
46
- presets,
47
- recurringEvents,
48
- onChange,
49
- }: SuperDateProps) => {
36
+ export function SuperDateTabs({ events, value, presets, recurringEvents, onChange }: SuperDateProps) {
50
37
  const { t } = useTranslation("superdate");
51
38
  const tree = useFloatingTree();
52
- const { currentCalendar, currentLocale } = useGlobals();
39
+ const { currentCalendar } = useApplicationContext();
53
40
 
54
41
  const isHijri = useMemo(() => currentCalendar === "hijri", [currentCalendar]);
55
42
 
@@ -57,74 +44,51 @@ export const SuperDateTabs = ({
57
44
  const [activeTab, setActiveTab] = useState("quick");
58
45
 
59
46
  useEffect(() => {
60
- if (value?.match(/^(\$\w+)([+-])(\d+)\|(\$\w+)([+-])(\d+)$/))
61
- setActiveTab("relative");
47
+ if (value?.match(/^(\$\w+)([+-])(\d+)\|(\$\w+)([+-])(\d+)$/)) setActiveTab("relative");
62
48
  else if (value && !value?.match(/^(\$\w+)/)) setActiveTab("absolute");
63
49
  else setActiveTab("quick");
64
50
 
65
- value && setCurrentValue(value);
51
+ if (value) setCurrentValue(value);
66
52
  }, [value]);
67
53
 
68
54
  const handleChange = useCallback(
69
55
  (value: string) => {
70
56
  const parsed = DateUtil.parseRange(value);
71
57
  setCurrentValue(value);
72
- onChange?.(value, [
73
- parsed[0]?.toISOString?.(),
74
- parsed[1]?.toISOString?.(),
75
- ]);
58
+ onChange?.(value, [parsed[0]?.toISOString?.(), parsed[1]?.toISOString?.()]);
76
59
  tree?.events.emit("close");
77
60
  },
78
- [isHijri, currentLocale],
61
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
62
+ [onChange],
79
63
  );
80
64
 
81
65
  return (
82
- <div
83
- className={classNames(
84
- "rounded-capped outline select-none overflow-hidden grid",
85
- "fabric-superDate",
86
- )}
87
- >
88
- <TabPanel
89
- headerClassName="border-b"
90
- onChange={setActiveTab}
91
- activeTab={activeTab}
92
- >
66
+ <div className={cn("rounded-capped outline select-none overflow-hidden grid", "fabric-superDate")}>
67
+ <TabPanel onChange={setActiveTab} activeTab={activeTab}>
93
68
  <Tab id="quick" label={t("label.quick")}>
94
- <QuickSelect
95
- value={currentValue}
96
- onChange={handleChange}
97
- presets={presets}
98
- />
69
+ <QuickSelect value={currentValue} onChange={handleChange} presets={presets} />
99
70
  </Tab>
100
71
  <Tab id="relative" label={t("label.relative")}>
101
72
  <RelativePanel value={currentValue} onChange={handleChange} />
102
73
  </Tab>
103
74
  <Tab id="absolute" label={t("label.absolute")}>
104
- <Content className="p-0">
75
+ <div className="p-0 overflow-hidden area-content">
105
76
  <RangePanel
106
77
  withTime
107
78
  showHijriToggle
108
- value={
109
- currentValue ? DateUtil.parseRange(currentValue) : undefined
110
- }
79
+ value={currentValue ? DateUtil.parseRange(currentValue) : undefined}
111
80
  {...({ showApply: true } as AnyObject)}
112
81
  onChange={([start, end]) => handleChange?.(`${start}|${end}`)}
113
82
  />
114
- </Content>
83
+ </div>
115
84
  </Tab>
116
85
  <Tab id="events" label={t("label.events")}>
117
- <EventPanel
118
- isHijri={isHijri}
119
- onChange={handleChange}
120
- events={events}
121
- recurringEvents={recurringEvents}
122
- />
86
+ <EventPanel isHijri={isHijri} onChange={handleChange} events={events} recurringEvents={recurringEvents} />
123
87
  </Tab>
124
88
  </TabPanel>
125
89
  </div>
126
90
  );
127
- };
91
+ }
128
92
 
129
93
  /**
130
94
  * SuperDate component provides a date selection interface with quick, relative, and absolute date options.
@@ -151,9 +115,6 @@ export const SuperDateTabs = ({
151
115
  * - `$week|$now`: Represents the current week starting from the beginning of the week to now.
152
116
  * - `$month|$week`: Represents the current month starting from the beginning of the month to the end of current week.
153
117
  *
154
- * @param {SuperDateProps} props - The properties for the SuperDate component.
155
- * @returns {JSX.Element} The rendered SuperDate component.
156
- *
157
118
  * @example
158
119
  * ```jsx
159
120
  * <SuperDate
@@ -169,42 +130,36 @@ export const SuperDateTabs = ({
169
130
  * data-testid="superdate"
170
131
  * />
171
132
  * ```
172
- *
173
- * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/superdate-superdate--docs}
174
133
  */
175
- export const SuperDate = ({
134
+ export function SuperDate({
176
135
  as = "button",
177
136
  color = "primary",
178
137
  size,
179
138
  variant,
180
139
  disabled,
181
- fullWidth,
182
140
  onChange,
183
141
  value,
184
142
  "data-test-value": testValue,
185
143
  "data-testid": testId,
186
144
  ...props
187
- }: SuperDateProps) => {
188
- const { currentCalendar, currentLocale } = useGlobals();
145
+ }: SuperDateProps) {
146
+ const { currentCalendar } = useApplicationContext();
189
147
 
190
148
  const isHijri = useMemo(() => currentCalendar === "hijri", [currentCalendar]);
191
149
 
192
- const [relValue, setRelative] = useState<string>();
150
+ const [relValue, setRelValue] = useState<string>();
193
151
 
194
152
  useEffect(() => {
195
- setRelative(value);
153
+ setRelValue(value);
196
154
  }, [value]);
197
155
 
198
156
  const handleChange = useCallback(
199
157
  (value: string) => {
200
158
  const parsed = DateUtil.parseRange(value);
201
- setRelative(value);
202
- onChange?.(value, [
203
- parsed[0]?.toISOString?.(),
204
- parsed[1]?.toISOString?.(),
205
- ]);
159
+ setRelValue(value);
160
+ onChange?.(value, [parsed[0]?.toISOString?.(), parsed[1]?.toISOString?.()]);
206
161
  },
207
- [isHijri, currentLocale],
162
+ [onChange],
208
163
  );
209
164
 
210
165
  const E = as === "button" ? Button : Chip;
@@ -214,10 +169,11 @@ export const SuperDate = ({
214
169
  <E
215
170
  icon="icon-[mdi--clock-outline]"
216
171
  size={size}
172
+ // @ts-expect-error ignore
217
173
  color={color}
174
+ // @ts-expect-error ignore
175
+ variant={variant}
218
176
  disabled={disabled}
219
- fullWidth={fullWidth}
220
- variant={variant as AnyObject}
221
177
  data-test-value={testValue}
222
178
  data-testid={testId}
223
179
  >
@@ -227,4 +183,4 @@ export const SuperDate = ({
227
183
  <SuperDateTabs {...props} value={relValue} onChange={handleChange} />
228
184
  </Dropdown>
229
185
  );
230
- };
186
+ }
@@ -21,11 +21,7 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import {
25
- type ColorState,
26
- type SizeType,
27
- type TestProps,
28
- } from "@react-fabric/core/dist/types/types";
24
+ import type { CustomColors, SizeType, TestProps } from "@react-fabric/core/dist/types/types";
29
25
 
30
26
  import { type EventType } from "@react-fabric/date/dist/types/types";
31
27
 
@@ -36,11 +32,10 @@ export interface PresetType {
36
32
 
37
33
  export interface SuperDateProps extends TestProps {
38
34
  as?: "button" | "chip";
39
- color?: ColorState;
35
+ color?: CustomColors;
40
36
  size?: SizeType;
41
- variant?: "solid" | "outline" | "link";
37
+ variant?: "solid" | "outlined" | "link" | "soft";
42
38
  disabled?: boolean;
43
- fullWidth?: boolean;
44
39
  /**
45
40
  * relative date value
46
41
  */