@frontify/fondue 12.0.0-beta.127 → 12.0.0-beta.129
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/DatePicker/DatePicker.d.ts +6 -2
- package/dist/components/DatePicker/DatePicker.es.js +118 -111
- package/dist/components/DatePicker/DatePicker.es.js.map +1 -1
- package/dist/components/DatePicker/DatePickerTrigger.es.js +15 -15
- package/dist/components/DatePicker/DatePickerTrigger.es.js.map +1 -1
- package/dist/components/Textarea/Textarea.es.js +47 -43
- package/dist/components/Textarea/Textarea.es.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.es.js +51 -51
- package/dist/components/Tooltip/Tooltip.es.js.map +1 -1
- package/dist/components/Tree/TreeItem.es.js +7 -7
- package/dist/components/Tree/TreeItem.es.js.map +1 -1
- package/dist/components/Trigger/Trigger.es.js +35 -31
- package/dist/components/Trigger/Trigger.es.js.map +1 -1
- package/dist/extractedThirdPartyStyles.css +5 -1
- package/dist/index.cjs.js +12 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.umd.js +7 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import DatepickerComponent, { ReactDatePicker } from 'react-datepicker';
|
|
2
3
|
import { Validation } from '../../utilities/validation';
|
|
3
4
|
type SingleDatePickerProps = {
|
|
4
5
|
variant?: 'single';
|
|
@@ -25,10 +26,13 @@ export type DatePickerProps = {
|
|
|
25
26
|
customTrigger?: React.ReactNode;
|
|
26
27
|
children?: React.ReactNode;
|
|
27
28
|
hasPopperArrow?: boolean;
|
|
29
|
+
preventOpenOnFocus?: boolean;
|
|
28
30
|
filterDate?: (date: Date) => boolean;
|
|
29
31
|
onOpen?: () => void;
|
|
30
32
|
onClose?: () => void;
|
|
31
33
|
onBlur?: () => void;
|
|
34
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
32
35
|
} & (SingleDatePickerProps | RangeDatePickerProps);
|
|
33
|
-
export
|
|
36
|
+
export type ReactDatePickerRef = ReactDatePicker<never, boolean>;
|
|
37
|
+
export declare const DatePicker: React.ForwardRefExoticComponent<DatePickerProps & React.RefAttributes<DatepickerComponent<never, boolean>>>;
|
|
34
38
|
export {};
|
|
@@ -1,117 +1,124 @@
|
|
|
1
1
|
import { IconSize as r } from "../../foundation/Icon/IconSize.es.js";
|
|
2
|
-
import { format as
|
|
3
|
-
import e, { useState as
|
|
4
|
-
import
|
|
2
|
+
import { format as v, getYear as A } from "date-fns";
|
|
3
|
+
import e, { forwardRef as H, useState as T } from "react";
|
|
4
|
+
import V from "react-datepicker";
|
|
5
5
|
import "./DatePicker.css.es.js";
|
|
6
|
-
import { DatePickerTrigger as
|
|
7
|
-
import { Validation as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
6
|
+
import { DatePickerTrigger as Y } from "./DatePickerTrigger.es.js";
|
|
7
|
+
import { Validation as q } from "../../utilities/validation.es.js";
|
|
8
|
+
import G from "../../foundation/Icon/Generated/IconCaretLeftDouble.es.js";
|
|
9
|
+
import J from "../../foundation/Icon/Generated/IconCaretLeft.es.js";
|
|
10
|
+
import K from "../../foundation/Icon/Generated/IconCaretRight.es.js";
|
|
11
|
+
import O from "../../foundation/Icon/Generated/IconCaretRightDouble.es.js";
|
|
12
12
|
import { Button as i } from "../Button/Button.es.js";
|
|
13
|
-
import { ButtonStyle as n, ButtonSize as
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
13
|
+
import { ButtonStyle as n, ButtonSize as o, ButtonEmphasis as s } from "../Button/ButtonTypes.es.js";
|
|
14
|
+
const Q = (m, a) => m === "single" ? a < new Date() ? "past-date" : "future-date" : "range-day", U = H(
|
|
15
|
+
({
|
|
16
|
+
placeHolder: m = "Select a date",
|
|
17
|
+
isClearable: a,
|
|
18
|
+
shouldCloseOnSelect: u,
|
|
19
|
+
onChange: d,
|
|
20
|
+
onOpen: l,
|
|
21
|
+
onClose: c,
|
|
22
|
+
onBlur: w,
|
|
23
|
+
onKeyDown: y,
|
|
24
|
+
dateFormat: D = "dd MMM yyyy",
|
|
25
|
+
value: k,
|
|
26
|
+
startDate: E,
|
|
27
|
+
endDate: g,
|
|
28
|
+
minDate: z,
|
|
29
|
+
maxDate: C,
|
|
30
|
+
validation: M = q.Default,
|
|
31
|
+
customTrigger: h,
|
|
32
|
+
children: S = /* @__PURE__ */ e.createElement(e.Fragment, null),
|
|
33
|
+
hasPopperArrow: I = !0,
|
|
34
|
+
preventOpenOnFocus: b = !1,
|
|
35
|
+
filterDate: N = () => !0,
|
|
36
|
+
variant: f = "single"
|
|
37
|
+
}, R) => {
|
|
38
|
+
const [W, p] = T(!1), x = () => {
|
|
39
|
+
p(!0), l == null || l();
|
|
40
|
+
}, B = () => {
|
|
41
|
+
p(!1), c == null || c();
|
|
42
|
+
};
|
|
43
|
+
return /* @__PURE__ */ e.createElement("div", { "data-test-id": "date-picker" }, /* @__PURE__ */ e.createElement(
|
|
44
|
+
V,
|
|
45
|
+
{
|
|
46
|
+
calendarClassName: "tw-rounded-sm tw-border tw-border-line-x-strong react-datepicker-wrap",
|
|
47
|
+
selected: k,
|
|
48
|
+
startDate: E,
|
|
49
|
+
endDate: g,
|
|
50
|
+
minDate: z,
|
|
51
|
+
maxDate: C,
|
|
52
|
+
calendarStartDay: 1,
|
|
53
|
+
onChange: d,
|
|
54
|
+
onKeyDown: y,
|
|
55
|
+
onBlur: w,
|
|
56
|
+
selectsRange: f === "range",
|
|
57
|
+
showPopperArrow: I,
|
|
58
|
+
preventOpenOnFocus: b,
|
|
59
|
+
filterDate: N,
|
|
60
|
+
customInput: h ?? /* @__PURE__ */ e.createElement(
|
|
61
|
+
Y,
|
|
62
|
+
{
|
|
63
|
+
isCalendarOpen: W,
|
|
64
|
+
isClearable: a,
|
|
65
|
+
placeHolder: m,
|
|
66
|
+
validation: M,
|
|
67
|
+
onDateChanged: d
|
|
68
|
+
}
|
|
69
|
+
),
|
|
70
|
+
ref: R,
|
|
71
|
+
formatWeekDay: (t) => t.slice(0, 1),
|
|
72
|
+
isClearable: a,
|
|
73
|
+
dateFormat: D,
|
|
74
|
+
onCalendarClose: B,
|
|
75
|
+
onCalendarOpen: x,
|
|
76
|
+
shouldCloseOnSelect: u,
|
|
77
|
+
dayClassName: (t) => Q(f, t),
|
|
78
|
+
renderCustomHeader: ({ date: t, decreaseMonth: P, increaseMonth: F, increaseYear: L, decreaseYear: j }) => /* @__PURE__ */ e.createElement("div", { className: "tw-flex tw-justify-between tw-pb-4 tw-px-0" }, /* @__PURE__ */ e.createElement(
|
|
79
|
+
i,
|
|
80
|
+
{
|
|
81
|
+
style: n.Default,
|
|
82
|
+
size: o.Medium,
|
|
83
|
+
onClick: j,
|
|
84
|
+
emphasis: s.Weak,
|
|
85
|
+
icon: /* @__PURE__ */ e.createElement(G, { size: r.Size20 })
|
|
86
|
+
}
|
|
87
|
+
), /* @__PURE__ */ e.createElement(
|
|
88
|
+
i,
|
|
89
|
+
{
|
|
90
|
+
style: n.Default,
|
|
91
|
+
size: o.Medium,
|
|
92
|
+
onClick: P,
|
|
93
|
+
emphasis: s.Weak,
|
|
94
|
+
icon: /* @__PURE__ */ e.createElement(J, { size: r.Size20 })
|
|
95
|
+
}
|
|
96
|
+
), /* @__PURE__ */ e.createElement("p", { className: "tw-font-sans tw-font-semibold tw-grow tw-self-center" }, v(t, "MMMM"), " ", A(t)), /* @__PURE__ */ e.createElement(
|
|
97
|
+
i,
|
|
98
|
+
{
|
|
99
|
+
style: n.Default,
|
|
100
|
+
size: o.Medium,
|
|
101
|
+
onClick: F,
|
|
102
|
+
emphasis: s.Weak,
|
|
103
|
+
icon: /* @__PURE__ */ e.createElement(K, { size: r.Size20 })
|
|
104
|
+
}
|
|
105
|
+
), /* @__PURE__ */ e.createElement(
|
|
106
|
+
i,
|
|
107
|
+
{
|
|
108
|
+
style: n.Default,
|
|
109
|
+
size: o.Medium,
|
|
110
|
+
onClick: L,
|
|
111
|
+
emphasis: s.Weak,
|
|
112
|
+
icon: /* @__PURE__ */ e.createElement(O, { size: r.Size20 })
|
|
113
|
+
}
|
|
114
|
+
))
|
|
115
|
+
},
|
|
116
|
+
S
|
|
117
|
+
));
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
U.displayName = "FondueDatePicker";
|
|
114
121
|
export {
|
|
115
|
-
|
|
122
|
+
U as DatePicker
|
|
116
123
|
};
|
|
117
124
|
//# sourceMappingURL=DatePicker.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.es.js","sources":["../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Button, ButtonEmphasis, ButtonSize, ButtonStyle } from '@components/Button';\nimport { IconSize } from '@foundation/Icon/IconSize';\nimport { format, getYear } from 'date-fns';\nimport React, { FC, useState } from 'react';\nimport DatepickerComponent from 'react-datepicker';\nimport './DatePicker.css';\nimport { DatePickerTrigger } from './DatePickerTrigger';\nimport { IconCaretLeft, IconCaretLeftDouble, IconCaretRight, IconCaretRightDouble } from '@foundation/Icon/Generated';\nimport { Validation } from '@utilities/validation';\n\ntype SingleDatePickerProps = {\n variant?: 'single';\n onChange: (date: Date | null) => void;\n startDate?: null;\n endDate?: null;\n};\n\ntype RangeDatePickerProps = {\n variant: 'range';\n onChange: (date: [Date | null, Date | null] | null) => void;\n startDate: Date | null;\n endDate: Date | null;\n};\n\nexport type DatePickerProps = {\n placeHolder?: string;\n isClearable?: boolean;\n shouldCloseOnSelect?: boolean;\n dateFormat?: string;\n /** @description when the variant is of type 'range', the value should be the startDate */\n value?: Date | null;\n minDate?: Date;\n maxDate?: Date;\n validation?: Validation;\n customTrigger?: React.ReactNode;\n children?: React.ReactNode;\n hasPopperArrow?: boolean;\n filterDate?: (date: Date) => boolean;\n onOpen?: () => void;\n onClose?: () => void;\n onBlur?: () => void;\n} & (SingleDatePickerProps | RangeDatePickerProps);\n\nconst getDayClasses = (variant: DatePickerProps['variant'], date: Date) => {\n if (variant === 'single') {\n return date < new Date() ? 'past-date' : 'future-date';\n }\n return 'range-day';\n};\n\nexport const DatePicker: FC<DatePickerProps> = ({\n placeHolder = 'Select a date',\n isClearable,\n shouldCloseOnSelect,\n onChange,\n onOpen,\n onClose,\n onBlur,\n dateFormat = 'dd MMM yyyy',\n value,\n startDate,\n endDate,\n minDate,\n maxDate,\n validation = Validation.Default,\n customTrigger,\n children = <></>,\n hasPopperArrow = true,\n filterDate = () => true,\n variant = 'single',\n}) => {\n const [isCalendarOpen, setIsCalendarOpen] = useState<boolean>(false);\n\n const handleOpen = () => {\n setIsCalendarOpen(true);\n onOpen?.();\n };\n\n const handleClose = () => {\n setIsCalendarOpen(false);\n onClose?.();\n };\n\n return (\n <div data-test-id=\"date-picker\">\n <DatepickerComponent\n calendarClassName=\"tw-rounded-sm tw-border tw-border-line-x-strong react-datepicker-wrap\"\n selected={value}\n startDate={startDate}\n endDate={endDate}\n minDate={minDate}\n maxDate={maxDate}\n calendarStartDay={1}\n onChange={onChange}\n onBlur={onBlur}\n selectsRange={variant === 'range' ? true : false}\n showPopperArrow={hasPopperArrow}\n filterDate={filterDate}\n customInput={\n customTrigger ?? (\n <DatePickerTrigger\n isCalendarOpen={isCalendarOpen}\n isClearable={isClearable}\n placeHolder={placeHolder}\n validation={validation}\n onDateChanged={onChange}\n />\n )\n }\n formatWeekDay={(day) => day.slice(0, 1)}\n isClearable={isClearable}\n dateFormat={dateFormat}\n onCalendarClose={handleClose}\n onCalendarOpen={handleOpen}\n shouldCloseOnSelect={shouldCloseOnSelect}\n dayClassName={(date) => getDayClasses(variant, date)}\n renderCustomHeader={({ date, decreaseMonth, increaseMonth, increaseYear, decreaseYear }) => (\n <div className=\"tw-flex tw-justify-between tw-pb-4 tw-px-0\">\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={decreaseYear}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretLeftDouble size={IconSize.Size20} />}\n />\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={decreaseMonth}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretLeft size={IconSize.Size20} />}\n />\n <p className=\"tw-font-sans tw-font-semibold tw-grow tw-self-center\">\n {format(date, 'MMMM')} {getYear(date)}\n </p>\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={increaseMonth}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretRight size={IconSize.Size20} />}\n />\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={increaseYear}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretRightDouble size={IconSize.Size20} />}\n />\n </div>\n )}\n >\n {children}\n </DatepickerComponent>\n </div>\n );\n};\nDatePicker.displayName = 'FondueDatePicker';\n"],"names":["getDayClasses","variant","date","DatePicker","placeHolder","isClearable","shouldCloseOnSelect","onChange","onOpen","onClose","onBlur","dateFormat","value","startDate","endDate","minDate","maxDate","validation","Validation","customTrigger","children","React","hasPopperArrow","filterDate","isCalendarOpen","setIsCalendarOpen","useState","handleOpen","handleClose","DatepickerComponent","DatePickerTrigger","day","decreaseMonth","increaseMonth","increaseYear","decreaseYear","Button","ButtonStyle","ButtonSize","ButtonEmphasis","IconCaretLeftDouble","IconSize","IconCaretLeft","format","getYear","IconCaretRight","IconCaretRightDouble"],"mappings":";;;;;;;;;;;;;AA6CA,MAAMA,IAAgB,CAACC,GAAqCC,MACpDD,MAAY,WACLC,IAAO,IAAI,SAAS,cAAc,gBAEtC,aAGEC,IAAkC,CAAC;AAAA,EAC5C,aAAAC,IAAc;AAAA,EACd,aAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,OAAAC;AAAA,EACA,WAAAC;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ACAjB,EAAW,cAAc;"}
|
|
1
|
+
{"version":3,"file":"DatePicker.es.js","sources":["../../../src/components/DatePicker/DatePicker.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Button, ButtonEmphasis, ButtonSize, ButtonStyle } from '@components/Button';\nimport { IconSize } from '@foundation/Icon/IconSize';\nimport { format, getYear } from 'date-fns';\nimport React, { forwardRef, useState } from 'react';\nimport DatepickerComponent, { ReactDatePicker } from 'react-datepicker';\nimport './DatePicker.css';\nimport { DatePickerTrigger } from './DatePickerTrigger';\nimport { IconCaretLeft, IconCaretLeftDouble, IconCaretRight, IconCaretRightDouble } from '@foundation/Icon/Generated';\nimport { Validation } from '@utilities/validation';\n\ntype SingleDatePickerProps = {\n variant?: 'single';\n onChange: (date: Date | null) => void;\n startDate?: null;\n endDate?: null;\n};\n\ntype RangeDatePickerProps = {\n variant: 'range';\n onChange: (date: [Date | null, Date | null] | null) => void;\n startDate: Date | null;\n endDate: Date | null;\n};\n\nexport type DatePickerProps = {\n placeHolder?: string;\n isClearable?: boolean;\n shouldCloseOnSelect?: boolean;\n dateFormat?: string;\n /** @description when the variant is of type 'range', the value should be the startDate */\n value?: Date | null;\n minDate?: Date;\n maxDate?: Date;\n validation?: Validation;\n customTrigger?: React.ReactNode;\n children?: React.ReactNode;\n hasPopperArrow?: boolean;\n preventOpenOnFocus?: boolean;\n filterDate?: (date: Date) => boolean;\n onOpen?: () => void;\n onClose?: () => void;\n onBlur?: () => void;\n onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;\n} & (SingleDatePickerProps | RangeDatePickerProps);\n\nconst getDayClasses = (variant: DatePickerProps['variant'], date: Date) => {\n if (variant === 'single') {\n return date < new Date() ? 'past-date' : 'future-date';\n }\n return 'range-day';\n};\n\nexport type ReactDatePickerRef = ReactDatePicker<never, boolean>;\n\nexport const DatePicker = forwardRef<ReactDatePicker<never, boolean>, DatePickerProps>(\n (\n {\n placeHolder = 'Select a date',\n isClearable,\n shouldCloseOnSelect,\n onChange,\n onOpen,\n onClose,\n onBlur,\n onKeyDown,\n dateFormat = 'dd MMM yyyy',\n value,\n startDate,\n endDate,\n minDate,\n maxDate,\n validation = Validation.Default,\n customTrigger,\n children = <></>,\n hasPopperArrow = true,\n preventOpenOnFocus = false,\n filterDate = () => true,\n variant = 'single',\n },\n ref,\n ) => {\n const [isCalendarOpen, setIsCalendarOpen] = useState<boolean>(false);\n\n const handleOpen = () => {\n setIsCalendarOpen(true);\n onOpen?.();\n };\n\n const handleClose = () => {\n setIsCalendarOpen(false);\n onClose?.();\n };\n\n return (\n <div data-test-id=\"date-picker\">\n <DatepickerComponent\n calendarClassName=\"tw-rounded-sm tw-border tw-border-line-x-strong react-datepicker-wrap\"\n selected={value}\n startDate={startDate}\n endDate={endDate}\n minDate={minDate}\n maxDate={maxDate}\n calendarStartDay={1}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onBlur={onBlur}\n selectsRange={variant === 'range' ? true : false}\n showPopperArrow={hasPopperArrow}\n preventOpenOnFocus={preventOpenOnFocus}\n filterDate={filterDate}\n customInput={\n customTrigger ?? (\n <DatePickerTrigger\n isCalendarOpen={isCalendarOpen}\n isClearable={isClearable}\n placeHolder={placeHolder}\n validation={validation}\n onDateChanged={onChange}\n />\n )\n }\n ref={ref}\n formatWeekDay={(day) => day.slice(0, 1)}\n isClearable={isClearable}\n dateFormat={dateFormat}\n onCalendarClose={handleClose}\n onCalendarOpen={handleOpen}\n shouldCloseOnSelect={shouldCloseOnSelect}\n dayClassName={(date) => getDayClasses(variant, date)}\n renderCustomHeader={({ date, decreaseMonth, increaseMonth, increaseYear, decreaseYear }) => (\n <div className=\"tw-flex tw-justify-between tw-pb-4 tw-px-0\">\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={decreaseYear}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretLeftDouble size={IconSize.Size20} />}\n />\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={decreaseMonth}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretLeft size={IconSize.Size20} />}\n />\n <p className=\"tw-font-sans tw-font-semibold tw-grow tw-self-center\">\n {format(date, 'MMMM')} {getYear(date)}\n </p>\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={increaseMonth}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretRight size={IconSize.Size20} />}\n />\n <Button\n style={ButtonStyle.Default}\n size={ButtonSize.Medium}\n onClick={increaseYear}\n emphasis={ButtonEmphasis.Weak}\n icon={<IconCaretRightDouble size={IconSize.Size20} />}\n />\n </div>\n )}\n >\n {children}\n </DatepickerComponent>\n </div>\n );\n },\n);\n\nDatePicker.displayName = 'FondueDatePicker';\n"],"names":["getDayClasses","variant","date","DatePicker","forwardRef","placeHolder","isClearable","shouldCloseOnSelect","onChange","onOpen","onClose","onBlur","onKeyDown","dateFormat","value","startDate","endDate","minDate","maxDate","validation","Validation","customTrigger","children","React","hasPopperArrow","preventOpenOnFocus","filterDate","ref","isCalendarOpen","setIsCalendarOpen","useState","handleOpen","handleClose","DatepickerComponent","DatePickerTrigger","day","decreaseMonth","increaseMonth","increaseYear","decreaseYear","Button","ButtonStyle","ButtonSize","ButtonEmphasis","IconCaretLeftDouble","IconSize","IconCaretLeft","format","getYear","IconCaretRight","IconCaretRightDouble"],"mappings":";;;;;;;;;;;;;AA+CA,MAAMA,IAAgB,CAACC,GAAqCC,MACpDD,MAAY,WACLC,IAAO,IAAI,SAAS,cAAc,gBAEtC,aAKEC,IAAaC;AAAA,EACtB,CACI;AAAA,IACI,aAAAC,IAAc;AAAA,IACd,aAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,UAAAC;AAAA,IACA,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAAC;AAAA,IACA,WAAAC;AAAA,IACA,YAAAC,IAAa;AAAA,IACb,OAAAC;AAAA,IACA,WAAAC;AAAA,IACA,SAAAC;AAA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UAAA;AAAA,QAAA,CAE3D;AAAA,MAAA;AAAA,MAGHvB;AAAA,IAAA,CAET;AAAA,EAER;AACJ;AAEAnB,EAAW,cAAc;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { merge as
|
|
2
|
-
import { Validation as
|
|
1
|
+
import { merge as s } from "../../utilities/merge.es.js";
|
|
2
|
+
import { Validation as e } from "../../utilities/validation.es.js";
|
|
3
3
|
import t, { forwardRef as h } from "react";
|
|
4
4
|
import S from "../../foundation/Icon/Generated/IconCaretUp.es.js";
|
|
5
5
|
import { IconSize as l } from "../../foundation/Icon/IconSize.es.js";
|
|
@@ -7,8 +7,8 @@ import z from "../../foundation/Icon/Generated/IconCaretDown.es.js";
|
|
|
7
7
|
import { TextInput as F } from "../TextInput/TextInput.es.js";
|
|
8
8
|
import R from "../../foundation/Icon/Generated/IconCalendar.es.js";
|
|
9
9
|
const I = h(
|
|
10
|
-
({ value:
|
|
11
|
-
const w =
|
|
10
|
+
({ value: o, onClick: a, isClearable: i, placeHolder: m, isCalendarOpen: f, validation: r = e.Default, onDateChanged: n }, d) => {
|
|
11
|
+
const w = r === e.Error || r === e.Warning, g = "tw-right-14", p = "tw-right-8", E = "tw-right-4", c = ((u) => {
|
|
12
12
|
switch (u) {
|
|
13
13
|
case 0:
|
|
14
14
|
return E;
|
|
@@ -19,25 +19,25 @@ const I = h(
|
|
|
19
19
|
}
|
|
20
20
|
return "";
|
|
21
21
|
})(
|
|
22
|
-
(
|
|
22
|
+
(o && i ? 1 : 0) + (w ? 1 : 0)
|
|
23
23
|
);
|
|
24
24
|
return /* @__PURE__ */ t.createElement("div", { ref: d, "aria-hidden": "true" }, /* @__PURE__ */ t.createElement(
|
|
25
25
|
"div",
|
|
26
26
|
{
|
|
27
|
-
className:
|
|
27
|
+
className: s([
|
|
28
28
|
"tw-absolute tw-top-2 tw-text-black-60 tw-z-[1]",
|
|
29
|
-
|
|
29
|
+
c
|
|
30
30
|
])
|
|
31
31
|
},
|
|
32
32
|
f ? /* @__PURE__ */ t.createElement(S, { size: l.Size20 }) : /* @__PURE__ */ t.createElement(z, { size: l.Size20 })
|
|
33
33
|
), /* @__PURE__ */ t.createElement(
|
|
34
34
|
"div",
|
|
35
35
|
{
|
|
36
|
-
className:
|
|
36
|
+
className: s([
|
|
37
37
|
"tw-absolute tw-top-0 tw-left-0 tw-bottom-0 tw-z-10",
|
|
38
|
-
|
|
38
|
+
c
|
|
39
39
|
]),
|
|
40
|
-
onClick:
|
|
40
|
+
onClick: a,
|
|
41
41
|
"data-test-id": "open-close-click-zone"
|
|
42
42
|
}
|
|
43
43
|
), /* @__PURE__ */ t.createElement(
|
|
@@ -45,13 +45,13 @@ const I = h(
|
|
|
45
45
|
{
|
|
46
46
|
decorator: /* @__PURE__ */ t.createElement(R, null),
|
|
47
47
|
placeholder: m,
|
|
48
|
-
value:
|
|
49
|
-
clearable:
|
|
50
|
-
onEnterPressed:
|
|
48
|
+
value: o,
|
|
49
|
+
clearable: i,
|
|
50
|
+
onEnterPressed: a,
|
|
51
51
|
onClear: () => {
|
|
52
|
-
|
|
52
|
+
n && n(null);
|
|
53
53
|
},
|
|
54
|
-
validation:
|
|
54
|
+
validation: r
|
|
55
55
|
}
|
|
56
56
|
));
|
|
57
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePickerTrigger.es.js","sources":["../../../src/components/DatePicker/DatePickerTrigger.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { TextInput } from '@components/TextInput';\nimport { IconCalendar } from '@foundation/Icon/Generated';\nimport { IconCaretDown, IconCaretUp, IconSize } from '@foundation/Icon/index';\nimport { merge } from '@utilities/merge';\nimport { Validation } from '@utilities/validation';\nimport React, { PropsWithChildren, forwardRef } from 'react';\n\ntype DatePickerTriggerProps = PropsWithChildren<{\n placeHolder?: string;\n value?: string;\n isClearable?: boolean;\n isCalendarOpen?: boolean;\n onClick?: () => void;\n validation?: Validation;\n onDateChanged?: ((date: [Date | null, Date | null] | null) => void) | ((date: Date | null) => void);\n}>;\n\nexport const DatePickerTrigger = forwardRef<HTMLDivElement, DatePickerTriggerProps>(\n (\n { value, onClick, isClearable, placeHolder, isCalendarOpen, validation = Validation.Default, onDateChanged },\n ref,\n ) => {\n const
|
|
1
|
+
{"version":3,"file":"DatePickerTrigger.es.js","sources":["../../../src/components/DatePicker/DatePickerTrigger.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { TextInput } from '@components/TextInput';\nimport { IconCalendar } from '@foundation/Icon/Generated';\nimport { IconCaretDown, IconCaretUp, IconSize } from '@foundation/Icon/index';\nimport { merge } from '@utilities/merge';\nimport { Validation } from '@utilities/validation';\nimport React, { PropsWithChildren, forwardRef } from 'react';\n\ntype DatePickerTriggerProps = PropsWithChildren<{\n placeHolder?: string;\n value?: string;\n isClearable?: boolean;\n isCalendarOpen?: boolean;\n onClick?: () => void;\n validation?: Validation;\n onDateChanged?: ((date: [Date | null, Date | null] | null) => void) | ((date: Date | null) => void);\n}>;\n\nexport const DatePickerTrigger = forwardRef<HTMLDivElement, DatePickerTriggerProps>(\n (\n { value, onClick, isClearable, placeHolder, isCalendarOpen, validation = Validation.Default, onDateChanged },\n ref,\n ) => {\n const isWarningOrErrorValidationState = validation === Validation.Error || validation === Validation.Warning;\n\n const twoSlotsAwayFromRightEdge = 'tw-right-14';\n const oneSlotAwayFromRightEdge = 'tw-right-8';\n const zeroSlotsAwayFromRightEdge = 'tw-right-4';\n\n const carrotRightSideTWPositionClassByOffset = (slotsOffsetFromRighSide: number): string => {\n switch (slotsOffsetFromRighSide) {\n case 0:\n return zeroSlotsAwayFromRightEdge;\n case 1:\n return oneSlotAwayFromRightEdge;\n case 2:\n return twoSlotsAwayFromRightEdge;\n }\n return '';\n };\n\n const carrotOffsetForClearButton = value && isClearable ? 1 : 0;\n const carrotOffsetForValidationErrorIcon = isWarningOrErrorValidationState ? 1 : 0;\n\n const carrotRightSideTWPositionClass = carrotRightSideTWPositionClassByOffset(\n carrotOffsetForClearButton + carrotOffsetForValidationErrorIcon,\n );\n\n /* eslint-disable jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */\n return (\n <div ref={ref} aria-hidden=\"true\">\n <div\n className={merge([\n 'tw-absolute tw-top-2 tw-text-black-60 tw-z-[1]',\n carrotRightSideTWPositionClass,\n ])}\n >\n {isCalendarOpen ? <IconCaretUp size={IconSize.Size20} /> : <IconCaretDown size={IconSize.Size20} />}\n </div>\n <div\n className={merge([\n 'tw-absolute tw-top-0 tw-left-0 tw-bottom-0 tw-z-10',\n carrotRightSideTWPositionClass,\n ])}\n onClick={onClick}\n data-test-id=\"open-close-click-zone\"\n ></div>\n <TextInput\n decorator={<IconCalendar />}\n placeholder={placeHolder}\n value={value}\n clearable={isClearable}\n onEnterPressed={onClick}\n onClear={() => {\n onDateChanged && onDateChanged(null);\n }}\n validation={validation}\n />\n </div>\n );\n /* eslint-enable jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */\n },\n);\n\nDatePickerTrigger.displayName = 'FondueDatePickerTrigger';\n"],"names":["DatePickerTrigger","forwardRef","value","onClick","isClearable","placeHolder","isCalendarOpen","validation","Validation","onDateChanged","ref","isWarningOrErrorValidationState","twoSlotsAwayFromRightEdge","oneSlotAwayFromRightEdge","zeroSlotsAwayFromRightEdge","carrotRightSideTWPositionClass","slotsOffsetFromRighSide","React","merge","IconCaretUp","IconSize","IconCaretDown","TextInput","IconCalendar"],"mappings":";;;;;;;;AAmBO,MAAMA,IAAoBC;AAAA,EAC7B,CACI,EAAE,OAAAC,GAAO,SAAAC,GAAS,aAAAC,GAAa,aAAAC,GAAa,gBAAAC,GAAgB,YAAAC,IAAaC,EAAW,SAAS,eAAAC,EAAc,GAC3GC,MACC;AACD,UAAMC,IAAkCJ,MAAeC,EAAW,SAASD,MAAeC,EAAW,SAE/FI,IAA4B,eAC5BC,IAA2B,cAC3BC,IAA6B,cAiB7BC,KAfyC,CAACC,MAA4C;AACxF,cAAQA,GAAyB;AAAA,QAC7B,KAAK;AACM,iBAAAF;AAAA,QACX,KAAK;AACM,iBAAAD;AAAA,QACX,KAAK;AACM,iBAAAD;AAAA,MACf;AACO,aAAA;AAAA,IAAA;AAAA,OAGwBV,KAASE,IAAc,IAAI,MACnBO,IAAkC,IAAI;AAAA,IAGhD;AAIjC,WACK,gBAAAM,EAAA,cAAA,OAAA,EAAI,KAAAP,GAAU,eAAY,UACvB,gBAAAO,EAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,WAAWC,EAAM;AAAA,UACb;AAAA,UACAH;AAAA,QAAA,CACH;AAAA,MAAA;AAAA,MAEAT,IAAkB,gBAAAW,EAAA,cAAAE,GAAA,EAAY,MAAMC,EAAS,OAAQ,CAAA,IAAM,gBAAAH,EAAA,cAAAI,GAAA,EAAc,MAAMD,EAAS,QAAQ;AAAA,IAErG,GAAA,gBAAAH,EAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,WAAWC,EAAM;AAAA,UACb;AAAA,UACAH;AAAA,QAAA,CACH;AAAA,QACD,SAAAZ;AAAA,QACA,gBAAa;AAAA,MAAA;AAAA,IAEjB,GAAA,gBAAAc,EAAA;AAAA,MAACK;AAAA,MAAA;AAAA,QACG,2CAAYC,GAAa,IAAA;AAAA,QACzB,aAAalB;AAAA,QACb,OAAAH;AAAA,QACA,WAAWE;AAAA,QACX,gBAAgBD;AAAA,QAChB,SAAS,MAAM;AACX,UAAAM,KAAiBA,EAAc,IAAI;AAAA,QACvC;AAAA,QACA,YAAAF;AAAA,MAAA;AAAA,IAAA,CAER;AAAA,EAGR;AACJ;AAEAP,EAAkB,cAAc;"}
|
|
@@ -1,76 +1,80 @@
|
|
|
1
|
-
import { useMemoizedId as
|
|
2
|
-
import { useFocusRing as
|
|
3
|
-
import { mergeProps as
|
|
4
|
-
import { FOCUS_STYLE as
|
|
5
|
-
import { merge as
|
|
6
|
-
import { validationClassMap as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { LoadingCircle as
|
|
11
|
-
const
|
|
12
|
-
id:
|
|
13
|
-
value:
|
|
1
|
+
import { useMemoizedId as h } from "../../hooks/useMemoizedId.es.js";
|
|
2
|
+
import { useFocusRing as z } from "@react-aria/focus";
|
|
3
|
+
import { mergeProps as C } from "@react-aria/utils";
|
|
4
|
+
import { FOCUS_STYLE as F } from "../../utilities/focusStyle.es.js";
|
|
5
|
+
import { merge as c } from "../../utilities/merge.es.js";
|
|
6
|
+
import { validationClassMap as L, Validation as e } from "../../utilities/validation.es.js";
|
|
7
|
+
import r from "react";
|
|
8
|
+
import S from "react-textarea-autosize";
|
|
9
|
+
import I from "../../foundation/Icon/Generated/IconExclamationMarkTriangle.es.js";
|
|
10
|
+
import { LoadingCircle as M, LoadingCircleSize as P } from "../LoadingCircle/LoadingCircle.es.js";
|
|
11
|
+
const v = ({
|
|
12
|
+
id: p,
|
|
13
|
+
value: u,
|
|
14
14
|
required: d = !1,
|
|
15
15
|
decorator: o,
|
|
16
|
-
placeholder:
|
|
16
|
+
placeholder: f,
|
|
17
17
|
disabled: l = !1,
|
|
18
18
|
onInput: s,
|
|
19
|
-
onBlur:
|
|
20
|
-
validation:
|
|
21
|
-
minRows:
|
|
22
|
-
maxRows:
|
|
19
|
+
onBlur: m,
|
|
20
|
+
validation: t = e.Default,
|
|
21
|
+
minRows: i,
|
|
22
|
+
maxRows: b,
|
|
23
23
|
autosize: n = !1,
|
|
24
|
-
resizeable:
|
|
24
|
+
resizeable: x = !0,
|
|
25
25
|
onFocus: w,
|
|
26
|
-
selectable:
|
|
26
|
+
selectable: g = !1
|
|
27
27
|
}) => {
|
|
28
|
-
const
|
|
29
|
-
return /* @__PURE__ */
|
|
28
|
+
const E = n ? S : "textarea", { isFocusVisible: k, focusProps: N } = z({ isTextInput: !0 }), T = { maxRows: b, minRows: i };
|
|
29
|
+
return /* @__PURE__ */ r.createElement("div", { className: "tw-relative" }, o && /* @__PURE__ */ r.createElement(
|
|
30
30
|
"div",
|
|
31
31
|
{
|
|
32
32
|
className: "tw-absolute tw-top-2 tw-left-2 tw-inline-flex tw-items-end tw-text-black-80",
|
|
33
33
|
"data-test-id": "decorator"
|
|
34
34
|
},
|
|
35
35
|
o
|
|
36
|
-
), /* @__PURE__ */
|
|
37
|
-
|
|
36
|
+
), /* @__PURE__ */ r.createElement(
|
|
37
|
+
E,
|
|
38
38
|
{
|
|
39
|
-
...
|
|
40
|
-
onBlur: (
|
|
41
|
-
onInput: (
|
|
39
|
+
...C(N, {
|
|
40
|
+
onBlur: (a) => m && m(a.target.value),
|
|
41
|
+
onInput: (a) => s && s(a.target.value)
|
|
42
42
|
}),
|
|
43
|
-
...n ?
|
|
44
|
-
id:
|
|
45
|
-
value:
|
|
46
|
-
placeholder:
|
|
43
|
+
...n ? T : { rows: i },
|
|
44
|
+
id: h(p),
|
|
45
|
+
value: u,
|
|
46
|
+
placeholder: f,
|
|
47
47
|
required: d,
|
|
48
|
-
className:
|
|
48
|
+
className: c([
|
|
49
49
|
"tw-w-full tw-p-2 tw-border tw-rounded tw-text-s tw-outline-none tw-transition tw-placeholder-black-60",
|
|
50
50
|
!!o && "tw-pl-7 ",
|
|
51
51
|
l ? "tw-border-black-5 tw-bg-black-5 tw-text-black-40" : "tw-text-black tw-border-black-20 hover:tw-border-black-90",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
!
|
|
55
|
-
|
|
52
|
+
k && F,
|
|
53
|
+
L[t],
|
|
54
|
+
!x && "tw-resize-none",
|
|
55
|
+
t === e.Error && "tw-pr-8"
|
|
56
56
|
]),
|
|
57
57
|
disabled: l,
|
|
58
|
-
onFocus: (
|
|
59
|
-
|
|
58
|
+
onFocus: (a) => {
|
|
59
|
+
g && a.target.select(), w && w(a);
|
|
60
60
|
},
|
|
61
61
|
"data-test-id": "textarea"
|
|
62
62
|
}
|
|
63
|
-
),
|
|
63
|
+
), t === e.Loading && /* @__PURE__ */ r.createElement("span", { className: "tw-absolute tw-top-[-0.55rem] tw-right-[-0.55rem] tw-bg-white tw-rounded-full tw-p-[2px] tw-border tw-border-black-10" }, /* @__PURE__ */ r.createElement(M, { size: P.ExtraSmall })), (t === e.Error || t === e.Warning) && /* @__PURE__ */ r.createElement(
|
|
64
64
|
"span",
|
|
65
65
|
{
|
|
66
|
-
className:
|
|
66
|
+
className: c([
|
|
67
|
+
"tw-absolute tw-top-[0.6rem] tw-right-[0.6rem]",
|
|
68
|
+
t === e.Error && "tw-text-text-negative",
|
|
69
|
+
t === e.Warning && "tw-text-text-warning"
|
|
70
|
+
]),
|
|
67
71
|
"data-test-id": "error-state-exclamation-mark-icon"
|
|
68
72
|
},
|
|
69
|
-
/* @__PURE__ */
|
|
73
|
+
/* @__PURE__ */ r.createElement(I, null)
|
|
70
74
|
));
|
|
71
75
|
};
|
|
72
|
-
|
|
76
|
+
v.displayName = "FondueTextarea";
|
|
73
77
|
export {
|
|
74
|
-
|
|
78
|
+
v as Textarea
|
|
75
79
|
};
|
|
76
80
|
//# sourceMappingURL=Textarea.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.es.js","sources":["../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { useFocusRing } from '@react-aria/focus';\nimport { mergeProps } from '@react-aria/utils';\nimport { FOCUS_STYLE } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\nimport { Validation, validationClassMap } from '@utilities/validation';\nimport { LoadingCircle, LoadingCircleSize } from '@components/LoadingCircle';\nimport React, { FC, FocusEvent, FormEvent, ReactNode } from 'react';\nimport TextareaAutosize, { TextareaAutosizeProps } from 'react-textarea-autosize';\nimport { IconExclamationMarkTriangle } from '@foundation/Icon/Generated';\n\nexport type TextareaProps = {\n id?: string;\n value?: string;\n required?: boolean;\n decorator?: ReactNode;\n placeholder?: string;\n disabled?: boolean;\n onInput?: (value: string) => void;\n onBlur?: (value: string) => void;\n onFocus?: (e: FocusEvent<HTMLTextAreaElement>) => void;\n validation?: Validation;\n /** When autosize if false, this is used as 'rows' property for standard textarea */\n minRows?: number;\n /** When autosize if false, this property is ignored */\n maxRows?: number;\n autosize?: boolean;\n resizeable?: boolean;\n selectable?: boolean;\n};\n\nexport const Textarea: FC<TextareaProps> = ({\n id: propId,\n value,\n required = false,\n decorator,\n placeholder,\n disabled = false,\n onInput,\n onBlur,\n validation = Validation.Default,\n minRows,\n maxRows,\n autosize = false,\n resizeable = true,\n onFocus,\n selectable = false,\n}) => {\n const Component = autosize ? TextareaAutosize : 'textarea';\n\n const { isFocusVisible, focusProps } = useFocusRing({ isTextInput: true });\n\n const autosizeProps = { maxRows, minRows };\n\n return (\n <div className=\"tw-relative\">\n {decorator && (\n <div\n className=\"tw-absolute tw-top-2 tw-left-2 tw-inline-flex tw-items-end tw-text-black-80\"\n data-test-id=\"decorator\"\n >\n {decorator}\n </div>\n )}\n <Component\n {...(mergeProps(focusProps, {\n onBlur: (event: FocusEvent<HTMLTextAreaElement>) => onBlur && onBlur(event.target.value),\n onInput: (event: FormEvent<HTMLTextAreaElement>) =>\n onInput && onInput((event.target as HTMLTextAreaElement).value),\n }) as TextareaAutosizeProps)}\n {...(autosize ? autosizeProps : { rows: minRows })}\n id={useMemoizedId(propId)}\n value={value}\n placeholder={placeholder}\n required={required}\n className={merge([\n 'tw-w-full tw-p-2 tw-border tw-rounded tw-text-s tw-outline-none tw-transition tw-placeholder-black-60',\n !!decorator && 'tw-pl-7 ',\n disabled\n ? 'tw-border-black-5 tw-bg-black-5 tw-text-black-40'\n : 'tw-text-black tw-border-black-20 hover:tw-border-black-90',\n isFocusVisible && FOCUS_STYLE,\n validationClassMap[validation],\n !resizeable && 'tw-resize-none',\n validation === Validation.Error && 'tw-pr-8',\n ])}\n disabled={disabled}\n onFocus={(e) => {\n if (selectable) {\n e.target.select();\n }\n if (onFocus) {\n onFocus(e);\n }\n }}\n data-test-id=\"textarea\"\n />\n {validation === Validation.Loading && (\n <span className=\"tw-absolute tw-top-[-0.55rem] tw-right-[-0.55rem] tw-bg-white tw-rounded-full tw-p-[2px] tw-border tw-border-black-10\">\n <LoadingCircle size={LoadingCircleSize.ExtraSmall} />\n </span>\n )}\n {validation === Validation.Error && (\n <span\n className
|
|
1
|
+
{"version":3,"file":"Textarea.es.js","sources":["../../../src/components/Textarea/Textarea.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { useFocusRing } from '@react-aria/focus';\nimport { mergeProps } from '@react-aria/utils';\nimport { FOCUS_STYLE } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\nimport { Validation, validationClassMap } from '@utilities/validation';\nimport { LoadingCircle, LoadingCircleSize } from '@components/LoadingCircle';\nimport React, { FC, FocusEvent, FormEvent, ReactNode } from 'react';\nimport TextareaAutosize, { TextareaAutosizeProps } from 'react-textarea-autosize';\nimport { IconExclamationMarkTriangle } from '@foundation/Icon/Generated';\n\nexport type TextareaProps = {\n id?: string;\n value?: string;\n required?: boolean;\n decorator?: ReactNode;\n placeholder?: string;\n disabled?: boolean;\n onInput?: (value: string) => void;\n onBlur?: (value: string) => void;\n onFocus?: (e: FocusEvent<HTMLTextAreaElement>) => void;\n validation?: Validation;\n /** When autosize if false, this is used as 'rows' property for standard textarea */\n minRows?: number;\n /** When autosize if false, this property is ignored */\n maxRows?: number;\n autosize?: boolean;\n resizeable?: boolean;\n selectable?: boolean;\n};\n\nexport const Textarea: FC<TextareaProps> = ({\n id: propId,\n value,\n required = false,\n decorator,\n placeholder,\n disabled = false,\n onInput,\n onBlur,\n validation = Validation.Default,\n minRows,\n maxRows,\n autosize = false,\n resizeable = true,\n onFocus,\n selectable = false,\n}) => {\n const Component = autosize ? TextareaAutosize : 'textarea';\n\n const { isFocusVisible, focusProps } = useFocusRing({ isTextInput: true });\n\n const autosizeProps = { maxRows, minRows };\n\n return (\n <div className=\"tw-relative\">\n {decorator && (\n <div\n className=\"tw-absolute tw-top-2 tw-left-2 tw-inline-flex tw-items-end tw-text-black-80\"\n data-test-id=\"decorator\"\n >\n {decorator}\n </div>\n )}\n <Component\n {...(mergeProps(focusProps, {\n onBlur: (event: FocusEvent<HTMLTextAreaElement>) => onBlur && onBlur(event.target.value),\n onInput: (event: FormEvent<HTMLTextAreaElement>) =>\n onInput && onInput((event.target as HTMLTextAreaElement).value),\n }) as TextareaAutosizeProps)}\n {...(autosize ? autosizeProps : { rows: minRows })}\n id={useMemoizedId(propId)}\n value={value}\n placeholder={placeholder}\n required={required}\n className={merge([\n 'tw-w-full tw-p-2 tw-border tw-rounded tw-text-s tw-outline-none tw-transition tw-placeholder-black-60',\n !!decorator && 'tw-pl-7 ',\n disabled\n ? 'tw-border-black-5 tw-bg-black-5 tw-text-black-40'\n : 'tw-text-black tw-border-black-20 hover:tw-border-black-90',\n isFocusVisible && FOCUS_STYLE,\n validationClassMap[validation],\n !resizeable && 'tw-resize-none',\n validation === Validation.Error && 'tw-pr-8',\n ])}\n disabled={disabled}\n onFocus={(e) => {\n if (selectable) {\n e.target.select();\n }\n if (onFocus) {\n onFocus(e);\n }\n }}\n data-test-id=\"textarea\"\n />\n {validation === Validation.Loading && (\n <span className=\"tw-absolute tw-top-[-0.55rem] tw-right-[-0.55rem] tw-bg-white tw-rounded-full tw-p-[2px] tw-border tw-border-black-10\">\n <LoadingCircle size={LoadingCircleSize.ExtraSmall} />\n </span>\n )}\n {(validation === Validation.Error || validation === Validation.Warning) && (\n <span\n className={merge([\n 'tw-absolute tw-top-[0.6rem] tw-right-[0.6rem]',\n validation === Validation.Error && 'tw-text-text-negative',\n validation === Validation.Warning && 'tw-text-text-warning',\n ])}\n data-test-id=\"error-state-exclamation-mark-icon\"\n >\n <IconExclamationMarkTriangle />\n </span>\n )}\n </div>\n );\n};\nTextarea.displayName = 'FondueTextarea';\n"],"names":["Textarea","propId","value","required","decorator","placeholder","disabled","onInput","onBlur","validation","Validation","minRows","maxRows","autosize","resizeable","onFocus","selectable","Component","TextareaAutosize","isFocusVisible","focusProps","useFocusRing","autosizeProps","React","mergeProps","event","useMemoizedId","merge","FOCUS_STYLE","validationClassMap","e","LoadingCircle","LoadingCircleSize","IconExclamationMarkTriangle"],"mappings":";;;;;;;;;;AAiCO,MAAMA,IAA8B,CAAC;AAAA,EACxC,IAAIC;AAAA,EACJ,OAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC,IAAaC,EAAW;AAAA,EACxB,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,YAAAC,IAAa;AAAA,EACb,SAAAC;AAAA,EACA,YAAAC,IAAa;AACjB,MAAM;AACI,QAAAC,IAAYJ,IAAWK,IAAmB,YAE1C,EAAE,gBAAAC,GAAgB,YAAAC,EAAW,IAAIC,EAAa,EAAE,aAAa,IAAM,GAEnEC,IAAgB,EAAE,SAAAV,GAAS,SAAAD;AAEjC,SACK,gBAAAY,EAAA,cAAA,OAAA,EAAI,WAAU,cAAA,GACVnB,KACG,gBAAAmB,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAU;AAAA,MACV,gBAAa;AAAA,IAAA;AAAA,IAEZnB;AAAA,EAGT,GAAA,gBAAAmB,EAAA;AAAA,IAACN;AAAA,IAAA;AAAA,MACI,GAAIO,EAAWJ,GAAY;AAAA,QACxB,QAAQ,CAACK,MAA2CjB,KAAUA,EAAOiB,EAAM,OAAO,KAAK;AAAA,QACvF,SAAS,CAACA,MACNlB,KAAWA,EAASkB,EAAM,OAA+B,KAAK;AAAA,MAAA,CACrE;AAAA,MACA,GAAIZ,IAAWS,IAAgB,EAAE,MAAMX,EAAQ;AAAA,MAChD,IAAIe,EAAczB,CAAM;AAAA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