@transferwise/components 0.0.0-experimental-fa3aa98 → 0.0.0-experimental-f4a328f
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/build/Calendar/Calendar.js +16 -94
- package/build/Calendar/Calendar.js.map +1 -1
- package/build/Calendar/Calendar.messages.js +0 -12
- package/build/Calendar/Calendar.messages.js.map +1 -1
- package/build/Calendar/Calendar.messages.mjs +0 -12
- package/build/Calendar/Calendar.messages.mjs.map +1 -1
- package/build/Calendar/Calendar.mjs +17 -95
- package/build/Calendar/Calendar.mjs.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.js +1 -5
- package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.mjs +1 -5
- package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.js +0 -14
- package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.mjs +0 -14
- package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +19 -53
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +19 -53
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.js +0 -6
- package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs +0 -6
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +3 -8
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +3 -8
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +3 -8
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +3 -8
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.js +0 -7
- package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.mjs +0 -7
- package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
- package/build/Calendar/{TableLink → tableLink}/TableLink.js +11 -26
- package/build/Calendar/tableLink/TableLink.js.map +1 -0
- package/build/Calendar/{TableLink → tableLink}/TableLink.mjs +11 -26
- package/build/Calendar/tableLink/TableLink.mjs.map +1 -0
- package/build/DateLookup/DateLookup.js +9 -20
- package/build/DateLookup/DateLookup.js.map +1 -1
- package/build/DateLookup/DateLookup.mjs +9 -20
- package/build/DateLookup/DateLookup.mjs.map +1 -1
- package/build/Markup/Markup.js +137 -0
- package/build/Markup/Markup.js.map +1 -0
- package/build/Markup/Markup.mjs +132 -0
- package/build/Markup/Markup.mjs.map +1 -0
- package/build/Markup/constants.js +36 -0
- package/build/Markup/constants.js.map +1 -0
- package/build/Markup/constants.mjs +29 -0
- package/build/Markup/constants.mjs.map +1 -0
- package/build/Markup/utils/parseMarkup.js +236 -0
- package/build/Markup/utils/parseMarkup.js.map +1 -0
- package/build/Markup/utils/parseMarkup.mjs +231 -0
- package/build/Markup/utils/parseMarkup.mjs.map +1 -0
- package/build/Markup/utils/sanitise.js +114 -0
- package/build/Markup/utils/sanitise.js.map +1 -0
- package/build/Markup/utils/sanitise.mjs +111 -0
- package/build/Markup/utils/sanitise.mjs.map +1 -0
- package/build/i18n/en.json +0 -4
- package/build/i18n/en.json.js +0 -4
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +0 -4
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/index.js +4 -2
- package/build/index.js.map +1 -1
- package/build/index.mjs +2 -1
- package/build/index.mjs.map +1 -1
- package/build/main.css +78 -123
- package/build/styles/Calendar/Calendar.css +37 -112
- package/build/styles/Markup/Markup.css +28 -0
- package/build/styles/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
- package/build/styles/main.css +78 -123
- package/build/types/Body/Body.d.ts +2 -2
- package/build/types/Calendar/Calendar.d.ts +3 -16
- package/build/types/Calendar/Calendar.d.ts.map +1 -1
- package/build/types/Calendar/Calendar.messages.d.ts +0 -20
- package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
- package/build/types/Calendar/DateHeader/DateHeader.d.ts +0 -2
- package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +1 -5
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +0 -4
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +0 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +1 -2
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +1 -2
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +0 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
- package/build/types/Calendar/index.d.ts +0 -1
- package/build/types/Calendar/index.d.ts.map +1 -1
- package/build/types/Calendar/{TableLink → tableLink}/TableLink.d.ts +1 -3
- package/build/types/Calendar/tableLink/TableLink.d.ts.map +1 -0
- package/build/types/Calendar/tableLink/index.d.ts.map +1 -0
- package/build/types/DateLookup/DateLookup.d.ts +5 -24
- package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/DateLookup/index.d.ts +0 -1
- package/build/types/DateLookup/index.d.ts.map +1 -1
- package/build/types/IconButton/IconButton.d.ts +1 -1
- package/build/types/Markup/Markup.d.ts +18 -0
- package/build/types/Markup/Markup.d.ts.map +1 -0
- package/build/types/Markup/Markup.types.d.ts +77 -0
- package/build/types/Markup/Markup.types.d.ts.map +1 -0
- package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts +12 -0
- package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts.map +1 -0
- package/build/types/Markup/constants.d.ts +20 -0
- package/build/types/Markup/constants.d.ts.map +1 -0
- package/build/types/Markup/index.d.ts +3 -0
- package/build/types/Markup/index.d.ts.map +1 -0
- package/build/types/Markup/utils/parseMarkup.d.ts +8 -0
- package/build/types/Markup/utils/parseMarkup.d.ts.map +1 -0
- package/build/types/Markup/utils/sanitise.d.ts +4 -0
- package/build/types/Markup/utils/sanitise.d.ts.map +1 -0
- package/build/types/Title/Title.d.ts +2 -2
- package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
- package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
- package/build/types/common/DateUtils/index.d.ts +0 -2
- package/build/types/common/DateUtils/index.d.ts.map +1 -1
- package/build/types/index.d.ts +4 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +0 -8
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Calendar/Calendar.css +37 -112
- package/src/Calendar/Calendar.less +35 -5
- package/src/Calendar/Calendar.messages.ts +0 -21
- package/src/Calendar/Calendar.test.tsx +27 -288
- package/src/Calendar/Calendar.tsx +19 -136
- package/src/Calendar/DateHeader/DateHeader.tsx +0 -6
- package/src/Calendar/DayCalendar/DayCalendar.tsx +1 -33
- package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +28 -62
- package/src/Calendar/MonthCalendar/MonthCalendar.tsx +0 -8
- package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +3 -15
- package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +3 -15
- package/src/Calendar/YearCalendar/YearCalendar.tsx +0 -9
- package/src/Calendar/_stories/Calendar.story.tsx +4 -138
- package/src/Calendar/index.ts +0 -7
- package/src/Calendar/{TableLink → tableLink}/TableLink.tsx +14 -29
- package/src/DateLookup/DateLookup.test.tsx +37 -34
- package/src/DateLookup/DateLookup.tsx +13 -37
- package/src/DateLookup/_stories/DateLookup.story.tsx +2 -124
- package/src/DateLookup/index.ts +0 -6
- package/src/Markup/Markup.css +28 -0
- package/src/Markup/Markup.injection.test.tsx +163 -0
- package/src/Markup/Markup.less +29 -0
- package/src/Markup/Markup.test.tsx +463 -0
- package/src/Markup/Markup.tsx +169 -0
- package/src/Markup/Markup.types.ts +62 -0
- package/src/Markup/_stories/Markup.docs.mdx +75 -0
- package/src/Markup/_stories/Markup.security.docs.mdx +343 -0
- package/src/Markup/_stories/Markup.story.tsx +266 -0
- package/src/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
- package/src/Markup/_stories/Vulnerability/Vulnerability.tsx +30 -0
- package/src/Markup/constants.ts +41 -0
- package/src/Markup/index.ts +2 -0
- package/src/Markup/utils/parseMarkup.test.ts +706 -0
- package/src/Markup/utils/parseMarkup.ts +234 -0
- package/src/Markup/utils/sanitise.test.ts +497 -0
- package/src/Markup/utils/sanitise.ts +133 -0
- package/src/common/DateUtils/index.ts +0 -2
- package/src/i18n/en.json +0 -4
- package/src/index.ts +4 -3
- package/src/main.css +78 -123
- package/src/main.less +1 -0
- package/build/Calendar/TableLink/TableLink.js.map +0 -1
- package/build/Calendar/TableLink/TableLink.mjs.map +0 -1
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +0 -33
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +0 -1
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +0 -31
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +0 -1
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.js +0 -40
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.js.map +0 -1
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs +0 -38
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs.map +0 -1
- package/build/styles/Calendar/TableLink/TableLink.css +0 -115
- package/build/types/Calendar/Calendar.types.d.ts +0 -32
- package/build/types/Calendar/Calendar.types.d.ts.map +0 -1
- package/build/types/Calendar/TableLink/TableLink.d.ts.map +0 -1
- package/build/types/Calendar/TableLink/index.d.ts.map +0 -1
- package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +0 -3
- package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +0 -1
- package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts +0 -3
- package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts.map +0 -1
- package/src/Calendar/Calendar.disabledDates.test.tsx +0 -518
- package/src/Calendar/Calendar.types.ts +0 -35
- package/src/Calendar/TableLink/TableLink.css +0 -115
- package/src/Calendar/TableLink/TableLink.less +0 -68
- package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +0 -118
- package/src/Calendar/_stories/Calendar.test.story.tsx +0 -74
- package/src/DateLookup/DateLookup.disabledDates.test.tsx +0 -293
- package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +0 -108
- package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +0 -98
- package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +0 -45
- package/src/common/DateUtils/isDateDisabled/isDateDisabled.test.ts +0 -169
- package/src/common/DateUtils/isDateDisabled/isDateDisabled.ts +0 -59
- /package/build/types/Calendar/{TableLink → tableLink}/index.d.ts +0 -0
- /package/src/Calendar/{TableLink → tableLink}/index.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YearCalendarTable.mjs","sources":["../../../../src/Calendar/YearCalendar/Table/YearCalendarTable.tsx"],"sourcesContent":["import { formatDate } from '@transferwise/formatting';\nimport { useIntl } from 'react-intl';\n\nimport { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime';\nimport TableLink from '../../
|
|
1
|
+
{"version":3,"file":"YearCalendarTable.mjs","sources":["../../../../src/Calendar/YearCalendar/Table/YearCalendarTable.tsx"],"sourcesContent":["import { formatDate } from '@transferwise/formatting';\nimport { useIntl } from 'react-intl';\n\nimport { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime';\nimport TableLink from '../../tableLink';\n\ninterface YearCalendarTableProps {\n selectedDate: Date | null;\n min: Date | null;\n max: Date | null;\n viewYear: number;\n placeholder?: string;\n onSelect: (year: number) => void;\n}\n\nconst ROWS = 5;\nconst COLS = 4;\nconst YEAR_ONLY_FORMAT: Intl.DateTimeFormatOptions = { year: 'numeric' };\n\nconst YearCalendarTable = ({\n selectedDate,\n min,\n max,\n viewYear,\n placeholder,\n onSelect,\n}: YearCalendarTableProps) => {\n const { locale } = useIntl();\n const startYear = viewYear - (viewYear % 20);\n const getLink = (year: number) => {\n return (\n <TableLink\n item={year}\n type=\"year\"\n title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}\n active={isActive(year)}\n disabled={isDisabled(year)}\n today={isThisYear(year)}\n autofocus={autofocusYear === year}\n onClick={onSelect}\n />\n );\n };\n\n const isActive = (year: number) => {\n return !!(year === selectedDate?.getFullYear());\n };\n\n const isThisYear = (year: number) => {\n return year === new Date().getFullYear();\n };\n\n const isDisabled = (year: number) => {\n return !!((min && year < min.getFullYear()) || (max && year > max.getFullYear()));\n };\n\n const autofocusYear = (() => {\n const years = Array.from({ length: ROWS * COLS }, (_, index) => startYear + index);\n return getFocusableTime({ isActive, isNow: isThisYear, isDisabled, timeSpan: years });\n })();\n\n return (\n <table className=\"table table-condensed table-bordered tw-date-lookup-calendar m-b-0\">\n <thead className=\"sr-only\">\n <tr>\n <th colSpan={COLS}>{placeholder}</th>\n </tr>\n </thead>\n <tbody>\n {Array.from({ length: ROWS }, (_, rowIndex) => (\n <tr key={rowIndex}>\n {Array.from({ length: COLS }, (_, colIndex) => (\n <td key={colIndex}>{getLink(startYear + rowIndex * COLS + colIndex)}</td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n );\n};\n\nexport default YearCalendarTable;\n"],"names":["ROWS","COLS","YEAR_ONLY_FORMAT","year","YearCalendarTable","selectedDate","min","max","viewYear","placeholder","onSelect","locale","useIntl","startYear","getLink","_jsx","TableLink","item","type","title","formatDate","Date","active","isActive","disabled","isDisabled","today","isThisYear","autofocus","autofocusYear","onClick","getFullYear","years","Array","from","length","_","index","getFocusableTime","isNow","timeSpan","_jsxs","className","children","colSpan","rowIndex","colIndex"],"mappings":";;;;;;AAeA,MAAMA,IAAI,GAAG,CAAC;AACd,MAAMC,IAAI,GAAG,CAAC;AACd,MAAMC,gBAAgB,GAA+B;AAAEC,EAAAA,IAAI,EAAE;CAAW;AAExE,MAAMC,iBAAiB,GAAGA,CAAC;EACzBC,YAAY;EACZC,GAAG;EACHC,GAAG;EACHC,QAAQ;EACRC,WAAW;AACXC,EAAAA;AAAQ,CACe,KAAI;EAC3B,MAAM;AAAEC,IAAAA;GAAQ,GAAGC,OAAO,EAAE;AAC5B,EAAA,MAAMC,SAAS,GAAGL,QAAQ,GAAIA,QAAQ,GAAG,EAAG;EAC5C,MAAMM,OAAO,GAAIX,IAAY,IAAI;IAC/B,oBACEY,GAAA,CAACC,SAAS,EAAA;AACRC,MAAAA,IAAI,EAAEd,IAAK;AACXe,MAAAA,IAAI,EAAC,MAAM;AACXC,MAAAA,KAAK,EAAEC,UAAU,CAAC,IAAIC,IAAI,CAAClB,IAAI,EAAE,CAAC,CA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AA,EAAA;AAAO2B,MAAAA,SAAS,EAAC,SAAS;AAAAC,MAAAA,QAAA,eACxB5B,GAAA,CAAA,IAAA,EAAA;AAAA4B,QAAAA,QAAA,eACE5B,GAAA,CAAA,IAAA,EAAA;AAAI6B,UAAAA,OAAO,EAAE3C,IAAK;AAAA0C,UAAAA,QAAA,EAAElC;SAAgB;OAClC;KACC,CACP,eAAAM,GAAA,CAAA,OAAA,EAAA;AAAA4B,MAAAA,QAAA,EACGV,KAAK,CAACC,IAAI,CAAC;AAAEC,QAAAA,MAAM,EAAEnC;AAAI,OAAE,EAAE,CAACoC,CAAC,EAAES,QAAQ,kBACxC9B,GAAA,CAAA,IAAA,EAAA;AAAA4B,QAAAA,QAAA,EACGV,KAAK,CAACC,IAAI,CAAC;AAAEC,UAAAA,MAAM,EAAElC;AAAI,SAAE,EAAE,CAACmC,CAAC,EAAEU,QAAQ,kBACxC/B,GAAA,CAAA,IAAA,EAAA;UAAA4B,QAAA,EAAoB7B,OAAO,CAACD,SAAS,GAAGgC,QAAQ,GAAG5C,IAAI,GAAG6C,QAAQ;AAAC,SAAA,EAA1DA,QAA+D,CACzE;AAAC,OAAA,EAHKD,QAIL,CACL;AAAC,KACG,CACT;AAAA,GAAO,CAAC;AAEZ;;;;"}
|
|
@@ -29,7 +29,6 @@ let YearCalendar$1 = class YearCalendar extends React.PureComponent {
|
|
|
29
29
|
render() {
|
|
30
30
|
const {
|
|
31
31
|
selectedDate,
|
|
32
|
-
focusedDate,
|
|
33
32
|
min,
|
|
34
33
|
max,
|
|
35
34
|
viewYear,
|
|
@@ -38,19 +37,13 @@ let YearCalendar$1 = class YearCalendar extends React.PureComponent {
|
|
|
38
37
|
formatMessage
|
|
39
38
|
}
|
|
40
39
|
} = this.props;
|
|
41
|
-
const startYear = viewYear - viewYear % 20;
|
|
42
|
-
const isPreviousDisabled = !!(min && startYear - 1 < min.getFullYear());
|
|
43
|
-
const isNextDisabled = !!(max && startYear + 20 > max.getFullYear());
|
|
44
40
|
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
45
41
|
children: [/*#__PURE__*/jsxRuntime.jsx(DateHeader.default, {
|
|
46
42
|
dateMode: formatMessage(Calendar_messages.default.twentyYears),
|
|
47
|
-
isPreviousDisabled: isPreviousDisabled,
|
|
48
|
-
isNextDisabled: isNextDisabled,
|
|
49
43
|
onPreviousClick: this.selectPreviousYears,
|
|
50
44
|
onNextClick: this.selectNextYears
|
|
51
45
|
}), /*#__PURE__*/jsxRuntime.jsx(YearCalendarTable.default, {
|
|
52
46
|
selectedDate: selectedDate,
|
|
53
|
-
focusedDate: focusedDate,
|
|
54
47
|
min: min,
|
|
55
48
|
max: max,
|
|
56
49
|
viewYear: viewYear,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YearCalendar.js","sources":["../../../src/Calendar/YearCalendar/YearCalendar.tsx"],"sourcesContent":["import { PureComponent } from 'react';\nimport { injectIntl, type WrappedComponentProps } from '../../common/injectIntl';\n\nimport messages from '../Calendar.messages';\nimport DateHeader from '../DateHeader';\n\nimport YearCalendarTable from './Table';\n\ninterface YearCalendarProps extends WrappedComponentProps {\n selectedDate: Date | null;\n
|
|
1
|
+
{"version":3,"file":"YearCalendar.js","sources":["../../../src/Calendar/YearCalendar/YearCalendar.tsx"],"sourcesContent":["import { PureComponent } from 'react';\nimport { injectIntl, type WrappedComponentProps } from '../../common/injectIntl';\n\nimport messages from '../Calendar.messages';\nimport DateHeader from '../DateHeader';\n\nimport YearCalendarTable from './Table';\n\ninterface YearCalendarProps extends WrappedComponentProps {\n selectedDate: Date | null;\n min: Date | null;\n max: Date | null;\n viewYear: number;\n placeholder?: string;\n onSelect: () => void;\n onViewDateUpdate: (date: { year: number }) => void;\n}\n\nclass YearCalendar extends PureComponent<YearCalendarProps> {\n onYearSelect = (year: number) => {\n this.props.onViewDateUpdate({ year });\n this.props.onSelect();\n };\n\n selectPreviousYears = () => {\n this.props.onViewDateUpdate({ year: this.props.viewYear - 20 });\n };\n\n selectNextYears = () => {\n this.props.onViewDateUpdate({ year: this.props.viewYear + 20 });\n };\n\n render() {\n const {\n selectedDate,\n min,\n max,\n viewYear,\n placeholder,\n intl: { formatMessage },\n } = this.props;\n return (\n <>\n <DateHeader\n dateMode={formatMessage(messages.twentyYears)}\n onPreviousClick={this.selectPreviousYears}\n onNextClick={this.selectNextYears}\n />\n <YearCalendarTable\n selectedDate={selectedDate}\n min={min}\n max={max}\n viewYear={viewYear}\n placeholder={placeholder}\n onSelect={this.onYearSelect}\n />\n </>\n );\n }\n}\n\nexport default injectIntl(YearCalendar);\n"],"names":["YearCalendar","PureComponent","onYearSelect","year","props","onViewDateUpdate","onSelect","selectPreviousYears","viewYear","selectNextYears","render","selectedDate","min","max","placeholder","intl","formatMessage","_jsxs","_Fragment","children","_jsx","DateHeader","dateMode","messages","twentyYears","onPreviousClick","onNextClick","YearCalendarTable","injectIntl"],"mappings":";;;;;;;;;;;qBAkBA,MAAMA,YAAa,SAAQC,mBAAgC,CAAA;EACzDC,YAAY,GAAIC,IAAY,IAAI;AAC9B,IAAA,IAAI,CAACC,KAAK,CAACC,gBAAgB,CAAC;AAAEF,MAAAA;AAAI,KAAE,CAAC;AACrC,IAAA,IAAI,CAACC,KAAK,CAACE,QAAQ,EAAE;EACvB,CAAC;EAEDC,mBAAmB,GAAGA,MAAK;AACzB,IAAA,IAAI,CAACH,KAAK,CAACC,gBAAgB,CAAC;AAAEF,MAAAA,IAAI,EAAE,IAAI,CAACC,KAAK,CAACI,QAAQ,GAAG;AAAE,KAAE,CAAC;EACjE,CAAC;EAEDC,eAAe,GAAGA,MAAK;AACrB,IAAA,IAAI,CAACL,KAAK,CAACC,gBAAgB,CAAC;AAAEF,MAAAA,IAAI,EAAE,IAAI,CAACC,KAAK,CAACI,QAAQ,GAAG;AAAE,KAAE,CAAC;EACjE,CAAC;AAEDE,EAAAA,MAAMA,GAAA;IACJ,MAAM;MACJC,YAAY;MACZC,GAAG;MACHC,GAAG;MACHL,QAAQ;MACRM,WAAW;AACXC,MAAAA,IAAI,EAAE;AAAEC,QAAAA;AAAa;KACtB,GAAG,IAAI,CAACZ,KAAK;IACd,oBACEa,eAAA,CAAAC,mBAAA,EAAA;MAAAC,QAAA,EAAA,cACEC,cAAA,CAACC,kBAAU,EAAA;AACTC,QAAAA,QAAQ,EAAEN,aAAa,CAACO,yBAAQ,CAACC,WAAW,CAAE;QAC9CC,eAAe,EAAE,IAAI,CAAClB,mBAAoB;QAC1CmB,WAAW,EAAE,IAAI,CAACjB;AAAgB,OAAA,CAEpC,eAAAW,cAAA,CAACO,yBAAiB,EAAA;AAChBhB,QAAAA,YAAY,EAAEA,YAAa;AAC3BC,QAAAA,GAAG,EAAEA,GAAI;AACTC,QAAAA,GAAG,EAAEA,GAAI;AACTL,QAAAA,QAAQ,EAAEA,QAAS;AACnBM,QAAAA,WAAW,EAAEA,WAAY;QACzBR,QAAQ,EAAE,IAAI,CAACJ;AAAa,OAAA,CAEhC;AAAA,KAAA,CAAG;AAEP,EAAA;AACD;AAED,mBAAe0B,qBAAU,CAAC5B,cAAY,CAAC;;;;"}
|
|
@@ -25,7 +25,6 @@ class YearCalendar extends PureComponent {
|
|
|
25
25
|
render() {
|
|
26
26
|
const {
|
|
27
27
|
selectedDate,
|
|
28
|
-
focusedDate,
|
|
29
28
|
min,
|
|
30
29
|
max,
|
|
31
30
|
viewYear,
|
|
@@ -34,19 +33,13 @@ class YearCalendar extends PureComponent {
|
|
|
34
33
|
formatMessage
|
|
35
34
|
}
|
|
36
35
|
} = this.props;
|
|
37
|
-
const startYear = viewYear - viewYear % 20;
|
|
38
|
-
const isPreviousDisabled = !!(min && startYear - 1 < min.getFullYear());
|
|
39
|
-
const isNextDisabled = !!(max && startYear + 20 > max.getFullYear());
|
|
40
36
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
41
37
|
children: [/*#__PURE__*/jsx(DateHeader, {
|
|
42
38
|
dateMode: formatMessage(messages.twentyYears),
|
|
43
|
-
isPreviousDisabled: isPreviousDisabled,
|
|
44
|
-
isNextDisabled: isNextDisabled,
|
|
45
39
|
onPreviousClick: this.selectPreviousYears,
|
|
46
40
|
onNextClick: this.selectNextYears
|
|
47
41
|
}), /*#__PURE__*/jsx(YearCalendarTable, {
|
|
48
42
|
selectedDate: selectedDate,
|
|
49
|
-
focusedDate: focusedDate,
|
|
50
43
|
min: min,
|
|
51
44
|
max: max,
|
|
52
45
|
viewYear: viewYear,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YearCalendar.mjs","sources":["../../../src/Calendar/YearCalendar/YearCalendar.tsx"],"sourcesContent":["import { PureComponent } from 'react';\nimport { injectIntl, type WrappedComponentProps } from '../../common/injectIntl';\n\nimport messages from '../Calendar.messages';\nimport DateHeader from '../DateHeader';\n\nimport YearCalendarTable from './Table';\n\ninterface YearCalendarProps extends WrappedComponentProps {\n selectedDate: Date | null;\n
|
|
1
|
+
{"version":3,"file":"YearCalendar.mjs","sources":["../../../src/Calendar/YearCalendar/YearCalendar.tsx"],"sourcesContent":["import { PureComponent } from 'react';\nimport { injectIntl, type WrappedComponentProps } from '../../common/injectIntl';\n\nimport messages from '../Calendar.messages';\nimport DateHeader from '../DateHeader';\n\nimport YearCalendarTable from './Table';\n\ninterface YearCalendarProps extends WrappedComponentProps {\n selectedDate: Date | null;\n min: Date | null;\n max: Date | null;\n viewYear: number;\n placeholder?: string;\n onSelect: () => void;\n onViewDateUpdate: (date: { year: number }) => void;\n}\n\nclass YearCalendar extends PureComponent<YearCalendarProps> {\n onYearSelect = (year: number) => {\n this.props.onViewDateUpdate({ year });\n this.props.onSelect();\n };\n\n selectPreviousYears = () => {\n this.props.onViewDateUpdate({ year: this.props.viewYear - 20 });\n };\n\n selectNextYears = () => {\n this.props.onViewDateUpdate({ year: this.props.viewYear + 20 });\n };\n\n render() {\n const {\n selectedDate,\n min,\n max,\n viewYear,\n placeholder,\n intl: { formatMessage },\n } = this.props;\n return (\n <>\n <DateHeader\n dateMode={formatMessage(messages.twentyYears)}\n onPreviousClick={this.selectPreviousYears}\n onNextClick={this.selectNextYears}\n />\n <YearCalendarTable\n selectedDate={selectedDate}\n min={min}\n max={max}\n viewYear={viewYear}\n placeholder={placeholder}\n onSelect={this.onYearSelect}\n />\n </>\n );\n }\n}\n\nexport default injectIntl(YearCalendar);\n"],"names":["YearCalendar","PureComponent","onYearSelect","year","props","onViewDateUpdate","onSelect","selectPreviousYears","viewYear","selectNextYears","render","selectedDate","min","max","placeholder","intl","formatMessage","_jsxs","_Fragment","children","_jsx","DateHeader","dateMode","messages","twentyYears","onPreviousClick","onNextClick","YearCalendarTable","injectIntl"],"mappings":";;;;;;;AAkBA,MAAMA,YAAa,SAAQC,aAAgC,CAAA;EACzDC,YAAY,GAAIC,IAAY,IAAI;AAC9B,IAAA,IAAI,CAACC,KAAK,CAACC,gBAAgB,CAAC;AAAEF,MAAAA;AAAI,KAAE,CAAC;AACrC,IAAA,IAAI,CAACC,KAAK,CAACE,QAAQ,EAAE;EACvB,CAAC;EAEDC,mBAAmB,GAAGA,MAAK;AACzB,IAAA,IAAI,CAACH,KAAK,CAACC,gBAAgB,CAAC;AAAEF,MAAAA,IAAI,EAAE,IAAI,CAACC,KAAK,CAACI,QAAQ,GAAG;AAAE,KAAE,CAAC;EACjE,CAAC;EAEDC,eAAe,GAAGA,MAAK;AACrB,IAAA,IAAI,CAACL,KAAK,CAACC,gBAAgB,CAAC;AAAEF,MAAAA,IAAI,EAAE,IAAI,CAACC,KAAK,CAACI,QAAQ,GAAG;AAAE,KAAE,CAAC;EACjE,CAAC;AAEDE,EAAAA,MAAMA,GAAA;IACJ,MAAM;MACJC,YAAY;MACZC,GAAG;MACHC,GAAG;MACHL,QAAQ;MACRM,WAAW;AACXC,MAAAA,IAAI,EAAE;AAAEC,QAAAA;AAAa;KACtB,GAAG,IAAI,CAACZ,KAAK;IACd,oBACEa,IAAA,CAAAC,QAAA,EAAA;MAAAC,QAAA,EAAA,cACEC,GAAA,CAACC,UAAU,EAAA;AACTC,QAAAA,QAAQ,EAAEN,aAAa,CAACO,QAAQ,CAACC,WAAW,CAAE;QAC9CC,eAAe,EAAE,IAAI,CAAClB,mBAAoB;QAC1CmB,WAAW,EAAE,IAAI,CAACjB;AAAgB,OAAA,CAEpC,eAAAW,GAAA,CAACO,iBAAiB,EAAA;AAChBhB,QAAAA,YAAY,EAAEA,YAAa;AAC3BC,QAAAA,GAAG,EAAEA,GAAI;AACTC,QAAAA,GAAG,EAAEA,GAAI;AACTL,QAAAA,QAAQ,EAAEA,QAAS;AACnBM,QAAAA,WAAW,EAAEA,WAAY;QACzBR,QAAQ,EAAE,IAAI,CAACJ;AAAa,OAAA,CAEhC;AAAA,KAAA,CAAG;AAEP,EAAA;AACD;AAED,qBAAe0B,UAAU,CAAC5B,YAAY,CAAC;;;;"}
|
|
@@ -6,7 +6,6 @@ var clsx = require('clsx');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var reactIntl = require('react-intl');
|
|
8
8
|
var Calendar_messages = require('../Calendar.messages.js');
|
|
9
|
-
var SentimentSurface = require('../../SentimentSurface/SentimentSurface.js');
|
|
10
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
10
|
|
|
12
11
|
const TableLink = ({
|
|
@@ -15,11 +14,9 @@ const TableLink = ({
|
|
|
15
14
|
title,
|
|
16
15
|
longTitle,
|
|
17
16
|
active,
|
|
18
|
-
outOfRange,
|
|
19
17
|
disabled,
|
|
20
18
|
today,
|
|
21
19
|
autofocus,
|
|
22
|
-
disabledReasonId,
|
|
23
20
|
onClick
|
|
24
21
|
}) => {
|
|
25
22
|
const buttonRef = React.useRef(null);
|
|
@@ -33,40 +30,28 @@ const TableLink = ({
|
|
|
33
30
|
}, [autofocus]);
|
|
34
31
|
const onCalendarClick = event => {
|
|
35
32
|
event.preventDefault();
|
|
36
|
-
|
|
33
|
+
if (!disabled) {
|
|
34
|
+
onClick(item);
|
|
35
|
+
}
|
|
37
36
|
};
|
|
38
|
-
const isUnavailable = outOfRange || disabled;
|
|
39
37
|
const calculateAriaLabel = () => {
|
|
40
|
-
let label = longTitle || title || '';
|
|
41
38
|
if (active) {
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
if (isUnavailable) {
|
|
45
|
-
label += `, ${intl.formatMessage(Calendar_messages.default.notAvailable)}`;
|
|
39
|
+
return `${longTitle || title || ''}, ${intl.formatMessage(Calendar_messages.default.selected)} ${intl.formatMessage(Calendar_messages.default[type])}`;
|
|
46
40
|
}
|
|
47
|
-
return
|
|
41
|
+
return longTitle || title;
|
|
48
42
|
};
|
|
49
|
-
return /*#__PURE__*/jsxRuntime.jsx(
|
|
50
|
-
// @ts-expect-error - Generic forwardRef limitation in SentimentSurface
|
|
51
|
-
, {
|
|
43
|
+
return /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
52
44
|
ref: buttonRef,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"aria-describedby": isUnavailable ? disabledReasonId : undefined,
|
|
56
|
-
"aria-disabled": isUnavailable || undefined,
|
|
57
|
-
"aria-label": calculateAriaLabel(),
|
|
58
|
-
"aria-pressed": active,
|
|
59
|
-
className: clsx.clsx(`wds-Calendar__option--${type}`, `tw-date-lookup-${type}-option np-text-body-default-bold`, {
|
|
45
|
+
type: "button",
|
|
46
|
+
className: clsx.clsx(`tw-date-lookup-${type}-option np-text-body-default-bold`, {
|
|
60
47
|
active: !!active
|
|
61
48
|
}, {
|
|
62
49
|
today: !!today
|
|
63
|
-
}, {
|
|
64
|
-
disabled: !!isUnavailable
|
|
65
50
|
}),
|
|
66
|
-
|
|
67
|
-
sentiment: isUnavailable ? 'negative' : 'neutral',
|
|
51
|
+
disabled: disabled,
|
|
68
52
|
tabIndex: autofocus ? 0 : -1,
|
|
69
|
-
|
|
53
|
+
"aria-label": calculateAriaLabel(),
|
|
54
|
+
"aria-pressed": active,
|
|
70
55
|
onClick: onCalendarClick,
|
|
71
56
|
children: title || item
|
|
72
57
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableLink.js","sources":["../../../src/Calendar/tableLink/TableLink.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport messages from '../Calendar.messages';\n\ninterface TableLinkProps {\n item: number;\n type: 'day' | 'month' | 'year';\n title?: string;\n longTitle?: string;\n active: boolean;\n disabled: boolean;\n today: boolean;\n autofocus?: boolean;\n onClick: (item: number) => void;\n}\n\nconst TableLink = ({\n item,\n type,\n title,\n longTitle,\n active,\n disabled,\n today,\n autofocus,\n onClick,\n}: TableLinkProps) => {\n const buttonRef = useRef<HTMLButtonElement>(null);\n const intl = useIntl();\n\n useEffect(() => {\n if (autofocus) {\n setTimeout(() => {\n buttonRef.current?.focus();\n }, 0);\n }\n }, [autofocus]);\n\n const onCalendarClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n if (!disabled) {\n onClick(item);\n }\n };\n\n const calculateAriaLabel = () => {\n if (active) {\n return `${longTitle || title || ''}, ${intl.formatMessage(\n messages.selected,\n )} ${intl.formatMessage(messages[type])}`;\n }\n return longTitle || title;\n };\n\n return (\n <button\n ref={buttonRef}\n type=\"button\"\n className={clsx(\n `tw-date-lookup-${type}-option np-text-body-default-bold`,\n { active: !!active },\n { today: !!today },\n )}\n disabled={disabled}\n tabIndex={autofocus ? 0 : -1}\n aria-label={calculateAriaLabel()}\n aria-pressed={active}\n onClick={onCalendarClick}\n >\n {title || item}\n </button>\n );\n};\n\nexport default TableLink;\n"],"names":["TableLink","item","type","title","longTitle","active","disabled","today","autofocus","onClick","buttonRef","useRef","intl","useIntl","useEffect","setTimeout","current","focus","onCalendarClick","event","preventDefault","calculateAriaLabel","formatMessage","messages","selected","_jsx","ref","className","clsx","tabIndex","children"],"mappings":";;;;;;;;;;AAkBA,MAAMA,SAAS,GAAGA,CAAC;EACjBC,IAAI;EACJC,IAAI;EACJC,KAAK;EACLC,SAAS;E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nBuB,IAAAA,QAAQ,EAAErB,SAAS,GAAG,CAAC,GAAG,EAAG;IAC7B,YAAA,EAAYa,kBAAkB,EAAG;AACjC,IAAA,cAAA,EAAchB,MAAO;AACrBI,IAAAA,OAAO,EAAES,eAAgB;IAAAY,QAAA,EAExB3B,KAAK,IAAIF;AAAI,GACR,CAAC;AAEb;;;;"}
|
|
@@ -2,7 +2,6 @@ import { clsx } from 'clsx';
|
|
|
2
2
|
import { useRef, useEffect } from 'react';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
import messages from '../Calendar.messages.mjs';
|
|
5
|
-
import SentimentSurface from '../../SentimentSurface/SentimentSurface.mjs';
|
|
6
5
|
import { jsx } from 'react/jsx-runtime';
|
|
7
6
|
|
|
8
7
|
const TableLink = ({
|
|
@@ -11,11 +10,9 @@ const TableLink = ({
|
|
|
11
10
|
title,
|
|
12
11
|
longTitle,
|
|
13
12
|
active,
|
|
14
|
-
outOfRange,
|
|
15
13
|
disabled,
|
|
16
14
|
today,
|
|
17
15
|
autofocus,
|
|
18
|
-
disabledReasonId,
|
|
19
16
|
onClick
|
|
20
17
|
}) => {
|
|
21
18
|
const buttonRef = useRef(null);
|
|
@@ -29,40 +26,28 @@ const TableLink = ({
|
|
|
29
26
|
}, [autofocus]);
|
|
30
27
|
const onCalendarClick = event => {
|
|
31
28
|
event.preventDefault();
|
|
32
|
-
|
|
29
|
+
if (!disabled) {
|
|
30
|
+
onClick(item);
|
|
31
|
+
}
|
|
33
32
|
};
|
|
34
|
-
const isUnavailable = outOfRange || disabled;
|
|
35
33
|
const calculateAriaLabel = () => {
|
|
36
|
-
let label = longTitle || title || '';
|
|
37
34
|
if (active) {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (isUnavailable) {
|
|
41
|
-
label += `, ${intl.formatMessage(messages.notAvailable)}`;
|
|
35
|
+
return `${longTitle || title || ''}, ${intl.formatMessage(messages.selected)} ${intl.formatMessage(messages[type])}`;
|
|
42
36
|
}
|
|
43
|
-
return
|
|
37
|
+
return longTitle || title;
|
|
44
38
|
};
|
|
45
|
-
return /*#__PURE__*/jsx(
|
|
46
|
-
// @ts-expect-error - Generic forwardRef limitation in SentimentSurface
|
|
47
|
-
, {
|
|
39
|
+
return /*#__PURE__*/jsx("button", {
|
|
48
40
|
ref: buttonRef,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"aria-describedby": isUnavailable ? disabledReasonId : undefined,
|
|
52
|
-
"aria-disabled": isUnavailable || undefined,
|
|
53
|
-
"aria-label": calculateAriaLabel(),
|
|
54
|
-
"aria-pressed": active,
|
|
55
|
-
className: clsx(`wds-Calendar__option--${type}`, `tw-date-lookup-${type}-option np-text-body-default-bold`, {
|
|
41
|
+
type: "button",
|
|
42
|
+
className: clsx(`tw-date-lookup-${type}-option np-text-body-default-bold`, {
|
|
56
43
|
active: !!active
|
|
57
44
|
}, {
|
|
58
45
|
today: !!today
|
|
59
|
-
}, {
|
|
60
|
-
disabled: !!isUnavailable
|
|
61
46
|
}),
|
|
62
|
-
|
|
63
|
-
sentiment: isUnavailable ? 'negative' : 'neutral',
|
|
47
|
+
disabled: disabled,
|
|
64
48
|
tabIndex: autofocus ? 0 : -1,
|
|
65
|
-
|
|
49
|
+
"aria-label": calculateAriaLabel(),
|
|
50
|
+
"aria-pressed": active,
|
|
66
51
|
onClick: onCalendarClick,
|
|
67
52
|
children: title || item
|
|
68
53
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableLink.mjs","sources":["../../../src/Calendar/tableLink/TableLink.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport messages from '../Calendar.messages';\n\ninterface TableLinkProps {\n item: number;\n type: 'day' | 'month' | 'year';\n title?: string;\n longTitle?: string;\n active: boolean;\n disabled: boolean;\n today: boolean;\n autofocus?: boolean;\n onClick: (item: number) => void;\n}\n\nconst TableLink = ({\n item,\n type,\n title,\n longTitle,\n active,\n disabled,\n today,\n autofocus,\n onClick,\n}: TableLinkProps) => {\n const buttonRef = useRef<HTMLButtonElement>(null);\n const intl = useIntl();\n\n useEffect(() => {\n if (autofocus) {\n setTimeout(() => {\n buttonRef.current?.focus();\n }, 0);\n }\n }, [autofocus]);\n\n const onCalendarClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n if (!disabled) {\n onClick(item);\n }\n };\n\n const calculateAriaLabel = () => {\n if (active) {\n return `${longTitle || title || ''}, ${intl.formatMessage(\n messages.selected,\n )} ${intl.formatMessage(messages[type])}`;\n }\n return longTitle || title;\n };\n\n return (\n <button\n ref={buttonRef}\n type=\"button\"\n className={clsx(\n `tw-date-lookup-${type}-option np-text-body-default-bold`,\n { active: !!active },\n { today: !!today },\n )}\n disabled={disabled}\n tabIndex={autofocus ? 0 : -1}\n aria-label={calculateAriaLabel()}\n aria-pressed={active}\n onClick={onCalendarClick}\n >\n {title || item}\n </button>\n );\n};\n\nexport default TableLink;\n"],"names":["TableLink","item","type","title","longTitle","active","disabled","today","autofocus","onClick","buttonRef","useRef","intl","useIntl","useEffect","setTimeout","current","focus","onCalendarClick","event","preventDefault","calculateAriaLabel","formatMessage","messages","selected","_jsx","ref","className","clsx","tabIndex","children"],"mappings":";;;;;;AAkBA,MAAMA,SAAS,GAAGA,CAAC;EACjBC,IAAI;EACJC,IAAI;EACJC,KAAK;EACLC,SAAS;EACTC,MAAM;EACNC,QAAQ;EACRC,KAAK;EACLC,SAAS;AACTC,EAAAA;AAAO,CACQ,KAAI;AACnB,EAAA,MAAMC,SAAS,GAAGC,MAAM,CAAoB,IAAI,CAAC;AACjD,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;AAEtBC,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,IAAIN,SAAS,EAAE;AACbO,MAAAA,UAAU,CAAC,MAAK;AACdL,QAAAA,SAAS,CAACM,OAAO,EAAEC,KAAK,EAAE;MAC5B,CAAC,EAAE,CAAC,CAAC;AACP,IAAA;AACF,EAAA,CAAC,EAAE,CAACT,SAAS,CAAC,CAAC;EAEf,MAAMU,eAAe,GAAIC,KAA0C,IAAI;IACrEA,KAAK,CAACC,cAAc,EAAE;IACtB,IAAI,CAACd,QAAQ,EAAE;MACbG,OAAO,CAACR,IAAI,CAAC;AACf,IAAA;EACF,CAAC;EAED,MAAMoB,kBAAkB,GAAGA,MAAK;AAC9B,IAAA,IAAIhB,MAAM,EAAE;MACV,OAAO,CAAA,EAAGD,SAAS,IAAID,KAAK,IAAI,EAAE,CAAA,EAAA,EAAKS,IAAI,CAACU,aAAa,CACvDC,QAAQ,CAACC,QAAQ,CAClB,CAAA,CAAA,EAAIZ,IAAI,CAACU,aAAa,CAACC,QAAQ,CAACrB,IAAI,CAAC,CAAC,CAAA,CAAE;AAC3C,IAAA;IACA,OAAOE,SAAS,IAAID,KAAK;EAC3B,CAAC;AAED,EAAA,oBACEsB,GAAA,CAAA,QAAA,EAAA;AACEC,IAAAA,GAAG,EAAEhB,SAAU;AACfR,IAAAA,IAAI,EAAC,QAAQ;AACbyB,IAAAA,SAAS,EAAEC,IAAI,CACb,CAAA,eAAA,EAAkB1B,IAAI,mCAAmC,EACzD;MAAEG,MAAM,EAAE,CAAC,CAACA;AAAM,KAAE,EACpB;MAAEE,KAAK,EAAE,CAAC,CAACA;KAAO,CAClB;AACFD,IAAAA,QAAQ,EAAEA,QAAS;AACnBuB,IAAAA,QAAQ,EAAErB,SAAS,GAAG,CAAC,GAAG,EAAG;IAC7B,YAAA,EAAYa,kBAAkB,EAAG;AACjC,IAAA,cAAA,EAAchB,MAAO;AACrBI,IAAAA,OAAO,EAAES,eAAgB;IAAAY,QAAA,EAExB3B,KAAK,IAAIF;AAAI,GACR,CAAC;AAEb;;;;"}
|
|
@@ -123,19 +123,7 @@ class DateLookup extends React.PureComponent {
|
|
|
123
123
|
this.focusOn(fallbackElement);
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
-
handleDateChange =
|
|
127
|
-
const {
|
|
128
|
-
onDateSelect
|
|
129
|
-
} = this.props;
|
|
130
|
-
if (date && onDateSelect) {
|
|
131
|
-
onDateSelect({
|
|
132
|
-
date,
|
|
133
|
-
isEnabled: meta.isEnabled
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
handleDateSelect = date => {
|
|
138
|
-
if (!date) return;
|
|
126
|
+
handleDateChange = date => {
|
|
139
127
|
this.setState(state => {
|
|
140
128
|
const originalDate = state.originalDate ?? this.props.value;
|
|
141
129
|
return {
|
|
@@ -143,18 +131,20 @@ class DateLookup extends React.PureComponent {
|
|
|
143
131
|
};
|
|
144
132
|
}, () => {
|
|
145
133
|
this.props.onChange(date);
|
|
146
|
-
this.close();
|
|
147
|
-
this.focusOn('.btn');
|
|
148
134
|
});
|
|
149
135
|
};
|
|
136
|
+
handleDateSelect = date => {
|
|
137
|
+
this.props.onChange(date);
|
|
138
|
+
this.close();
|
|
139
|
+
this.focusOn('.btn');
|
|
140
|
+
};
|
|
150
141
|
getCalendar = () => {
|
|
151
142
|
const {
|
|
152
143
|
value,
|
|
153
144
|
min,
|
|
154
145
|
max,
|
|
155
146
|
monthFormat,
|
|
156
|
-
placeholder
|
|
157
|
-
disabledRules
|
|
147
|
+
placeholder
|
|
158
148
|
} = this.props;
|
|
159
149
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
160
150
|
className: "p-a-1",
|
|
@@ -164,9 +154,8 @@ class DateLookup extends React.PureComponent {
|
|
|
164
154
|
max: max,
|
|
165
155
|
monthFormat: monthFormat,
|
|
166
156
|
placeholder: placeholder,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
onChange: this.handleDateSelect
|
|
157
|
+
onChange: this.handleDateChange,
|
|
158
|
+
onSelect: this.handleDateSelect
|
|
170
159
|
})
|
|
171
160
|
});
|
|
172
161
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateLookup.js","sources":["../../src/DateLookup/DateLookup.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, PureComponent, KeyboardEvent } from 'react';\nimport Calendar from '../Calendar';\nimport type { DateChangeMeta, DisabledRules, OnDateSelectParams } from '../Calendar/Calendar.types';\nimport {\n Size,\n MonthFormat,\n Position,\n type SizeSmall,\n type SizeMedium,\n type SizeLarge,\n} from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport { WithInputAttributesProps, withInputAttributes } from '../Inputs/contexts';\nimport { OverlayIdProvider } from '../Provider/overlay/OverlayIdProvider';\nimport DateTrigger from './DateTrigger';\n\nexport interface DateLookupProps {\n /** The currently selected date, or `null` for no selection. */\n value: Date | null;\n /** Called when an enabled date is confirmed. Receives `null` when the value is cleared. */\n onChange: (date: Date | null) => void;\n /** HTML `id` applied to the trigger button, used for label association. */\n id?: string;\n /** Earliest selectable date (inclusive). Dates before this are interactive but not selectable, and show a boundary prompt. */\n min?: Date | null;\n /** Latest selectable date (inclusive). Dates after this are interactive but not selectable, and show a boundary prompt. */\n max?: Date | null;\n /** Size of the trigger input. Defaults to `'md'`. */\n size?: SizeSmall | SizeMedium | SizeLarge;\n /** Label text rendered above the trigger input. */\n label?: string;\n /** ID of an external element that labels the trigger, for use inside custom label contexts. */\n 'aria-labelledby'?: string;\n /** Placeholder text shown in the trigger when no date is selected. */\n placeholder?: string;\n /** Month name format in the calendar header. Defaults to `'long'` (e.g. \"January\"). */\n monthFormat?: `${MonthFormat}`;\n /** When `true`, the trigger and calendar are non-interactive. */\n disabled?: boolean;\n /** When `true`, a clear button is shown in the trigger to reset the value to `null`. */\n clearable?: boolean;\n /** Rules for disabling specific weekdays, individual dates, or date ranges. The required `reason` is shown in an inline prompt and linked to disabled cells via `aria-describedby` for screen reader accessibility. */\n disabledRules?: DisabledRules;\n /** Called whenever any date is focused or clicked, including disabled and out-of-range dates. `isEnabled` is `false` when the date is not selectable. */\n onDateSelect?: (params: OnDateSelectParams) => void;\n /** Called when the calendar panel opens. */\n onFocus?: () => void;\n /** Called when the calendar panel closes. */\n onBlur?: () => void;\n}\n\ntype DateLookupPropsWithInputAttributes = DateLookupProps & Partial<WithInputAttributesProps>;\n\ninterface DateLookupState {\n originalDate: Date | null;\n open: boolean;\n}\n\nclass DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateLookupState> {\n declare props: DateLookupPropsWithInputAttributes &\n Required<Pick<DateLookupPropsWithInputAttributes, keyof typeof DateLookup.defaultProps>>;\n\n static defaultProps = {\n value: null,\n min: null,\n max: null,\n size: Size.MEDIUM,\n placeholder: '',\n label: '',\n monthFormat: MonthFormat.LONG,\n disabled: false,\n clearable: false,\n } satisfies Partial<DateLookupPropsWithInputAttributes>;\n\n element = createRef<HTMLDivElement>();\n\n constructor(props: DateLookup['props']) {\n super(props);\n this.state = {\n originalDate: null,\n open: false,\n };\n }\n\n componentDidUpdate(previousProps: DateLookupPropsWithInputAttributes) {\n if (this.props.value?.getTime() !== previousProps.value?.getTime() && this.state.open) {\n this.focusOn('.active');\n }\n }\n\n open = () => {\n const { onFocus } = this.props;\n\n this.setState({ open: true });\n if (onFocus) {\n onFocus();\n }\n };\n\n discard = () => {\n const { originalDate } = this.state;\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n };\n\n close = () => {\n const { onBlur } = this.props;\n this.setState({ open: false, originalDate: null });\n if (onBlur) {\n onBlur();\n }\n };\n\n handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const { open, originalDate } = this.state;\n switch (event.key) {\n case 'ArrowLeft':\n case 'ArrowUp':\n case 'ArrowRight':\n case 'ArrowDown':\n if (!open) {\n this.open();\n event.preventDefault();\n }\n break;\n case 'Escape':\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n event.preventDefault();\n break;\n default:\n break;\n }\n };\n\n focusOn = (preferredElement: string, fallbackElement?: string) => {\n const element = this.element.current?.querySelector(preferredElement) as HTMLElement | null;\n if (element) {\n element.focus();\n } else if (fallbackElement) {\n this.focusOn(fallbackElement);\n }\n };\n\n handleDateChange = (date: Date | null, meta: DateChangeMeta) => {\n const { onDateSelect } = this.props;\n if (date && onDateSelect) {\n onDateSelect({ date, isEnabled: meta.isEnabled });\n }\n };\n\n handleDateSelect = (date: Date | null) => {\n if (!date) return;\n this.setState(\n (state) => {\n const originalDate = state.originalDate ?? this.props.value;\n return { originalDate };\n },\n () => {\n this.props.onChange(date);\n this.close();\n this.focusOn('.btn');\n },\n );\n };\n\n getCalendar = () => {\n const { value, min, max, monthFormat, placeholder, disabledRules } = this.props;\n return (\n <div className=\"p-a-1\">\n <Calendar\n value={value}\n min={min}\n max={max}\n monthFormat={monthFormat}\n placeholder={placeholder}\n disabledRules={disabledRules}\n onDateFocus={this.handleDateChange}\n onChange={this.handleDateSelect}\n />\n </div>\n );\n };\n\n handleClear = () => {\n this.props.onChange(null);\n this.focusOn('.np-date-trigger');\n };\n\n render() {\n const { open } = this.state;\n\n const {\n inputAttributes,\n id: idProp,\n 'aria-labelledby': ariaLabelledByProp,\n size,\n placeholder,\n label,\n monthFormat,\n disabled,\n clearable,\n value,\n } = this.props;\n const id = idProp ?? inputAttributes?.id;\n const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes?.['aria-labelledby'];\n\n return (\n <div\n ref={this.element}\n aria-labelledby={id}\n aria-invalid={inputAttributes?.['aria-invalid']}\n aria-describedby={inputAttributes?.['aria-describedby']}\n className={clsx('input-group', disabled && 'disabled')}\n onKeyDown={this.handleKeyDown}\n >\n <OverlayIdProvider open={open}>\n <DateTrigger\n id={id}\n ariaLabelledBy={ariaLabelledBy}\n selectedDate={value}\n size={size}\n placeholder={placeholder}\n label={label}\n monthFormat={monthFormat}\n disabled={disabled || false}\n onClick={this.open}\n onClear={!disabled && clearable && value ? this.handleClear : undefined}\n />\n <ResponsivePanel\n anchorRef={this.element}\n open={open}\n className=\"tw-date-lookup-menu\"\n position={Position.BOTTOM}\n considerHeight\n onClose={this.discard}\n >\n {this.getCalendar()}\n </ResponsivePanel>\n </OverlayIdProvider>\n </div>\n );\n }\n}\n\nexport const DateLookupWithoutInputAttributes = DateLookup;\n\nconst WrappedDateLookup = withInputAttributes(\n DateLookup as React.ComponentType<DateLookupPropsWithInputAttributes>,\n { nonLabelable: true },\n);\nWrappedDateLookup.displayName = 'DateLookup';\n\nexport default WrappedDateLookup;\n"],"names":["DateLookup","PureComponent","defaultProps","value","min","max","size","Size","MEDIUM","placeholder","label","monthFormat","MonthFormat","LONG","disabled","clearable","element","createRef","constructor","props","state","originalDate","open","componentDidUpdate","previousProps","getTime","focusOn","onFocus","setState","discard","onChange","close","onBlur","handleKeyDown","event","key","preventDefault","preferredElement","fallbackElement","current","querySelector","focus","handleDateChange","date","meta","onDateSelect","isEnabled","handleDateSelect","getCalendar","disabledRules","_jsx","className","children","Calendar","onDateFocus","handleClear","render","inputAttributes","id","idProp","ariaLabelledByProp","ariaLabelledBy","ref","clsx","onKeyDown","_jsxs","OverlayIdProvider","DateTrigger","selectedDate","onClick","onClear","undefined","ResponsivePanel","anchorRef","position","Position","BOTTOM","considerHeight","onClose","WrappedDateLookup","withInputAttributes","nonLabelable","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,MAAMA,UAAW,SAAQC,mBAAkE,CAAA;AAIzF,EAAA,OAAOC,YAAY,GAAG;AACpBC,IAAAA,KAAK,EAAE,IAAI;AACXC,IAAAA,GAAG,EAAE,IAAI;AACTC,IAAAA,GAAG,EAAE,IAAI;IACTC,IAAI,EAAEC,SAAI,CAACC,MAAM;AACjBC,IAAAA,WAAW,EAAE,EAAE;AACfC,IAAAA,KAAK,EAAE,EAAE;IACTC,WAAW,EAAEC,uBAAW,CAACC,IAAI;AAC7BC,IAAAA,QAAQ,EAAE,KAAK;AACfC,IAAAA,SAAS,EAAE;GAC0C;EAEvDC,OAAO,gBAAGC,eAAS,EAAkB;EAErCC,WAAAA,CAAYC,KAA0B,EAAA;IACpC,KAAK,CAACA,KAAK,CAAC;IAC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B;UAC/BuB,QAAQ,EAAEC,iBAAQ,CAACC,MAAO;UAC1BC,cAAc,EAAA,IAAA;UACdC,OAAO,EAAE,IAAI,CAACjD,OAAQ;AAAAuB,UAAAA,QAAA,EAErB,IAAI,CAACJ,WAAW;AAAE,SACJ,CACnB;OAAmB;AACrB,KAAK,CAAC;AAEV,EAAA;;AAKF,MAAM+B,iBAAiB,GAAGC,4BAAmB,CAC3ChF,UAAqE,EACrE;AAAEiF,EAAAA,YAAY,EAAE;AAAI,CAAE;AAExBF,iBAAiB,CAACG,WAAW,GAAG,YAAY;;;;"}
|
|
1
|
+
{"version":3,"file":"DateLookup.js","sources":["../../src/DateLookup/DateLookup.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, PureComponent, KeyboardEvent } from 'react';\nimport Calendar from '../Calendar';\nimport {\n Size,\n MonthFormat,\n Position,\n type SizeSmall,\n type SizeMedium,\n type SizeLarge,\n} from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport { WithInputAttributesProps, withInputAttributes } from '../Inputs/contexts';\nimport { OverlayIdProvider } from '../Provider/overlay/OverlayIdProvider';\nimport DateTrigger from './DateTrigger';\n\nexport interface DateLookupProps {\n id?: string;\n value: Date | null;\n min?: Date | null;\n max?: Date | null;\n size?: SizeSmall | SizeMedium | SizeLarge;\n placeholder?: string;\n label?: string;\n 'aria-labelledby'?: string;\n monthFormat?: `${MonthFormat}`;\n disabled?: boolean;\n clearable?: boolean;\n onChange: (date: Date | null) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n}\n\ntype DateLookupPropsWithInputAttributes = DateLookupProps & Partial<WithInputAttributesProps>;\n\ninterface DateLookupState {\n originalDate: Date | null;\n open: boolean;\n}\n\nclass DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateLookupState> {\n declare props: DateLookupPropsWithInputAttributes &\n Required<Pick<DateLookupPropsWithInputAttributes, keyof typeof DateLookup.defaultProps>>;\n\n static defaultProps = {\n value: null,\n min: null,\n max: null,\n size: Size.MEDIUM,\n placeholder: '',\n label: '',\n monthFormat: MonthFormat.LONG,\n disabled: false,\n clearable: false,\n } satisfies Partial<DateLookupPropsWithInputAttributes>;\n\n element = createRef<HTMLDivElement>();\n\n constructor(props: DateLookup['props']) {\n super(props);\n this.state = {\n originalDate: null,\n open: false,\n };\n }\n\n componentDidUpdate(previousProps: DateLookupPropsWithInputAttributes) {\n if (this.props.value?.getTime() !== previousProps.value?.getTime() && this.state.open) {\n this.focusOn('.active');\n }\n }\n\n open = () => {\n const { onFocus } = this.props;\n\n this.setState({ open: true });\n if (onFocus) {\n onFocus();\n }\n };\n\n discard = () => {\n const { originalDate } = this.state;\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n };\n\n close = () => {\n const { onBlur } = this.props;\n this.setState({ open: false, originalDate: null });\n if (onBlur) {\n onBlur();\n }\n };\n\n handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const { open, originalDate } = this.state;\n switch (event.key) {\n case 'ArrowLeft':\n case 'ArrowUp':\n case 'ArrowRight':\n case 'ArrowDown':\n if (!open) {\n this.open();\n event.preventDefault();\n }\n break;\n case 'Escape':\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n event.preventDefault();\n break;\n default:\n break;\n }\n };\n\n focusOn = (preferredElement: string, fallbackElement?: string) => {\n const element = this.element.current?.querySelector(preferredElement) as HTMLElement | null;\n if (element) {\n element.focus();\n } else if (fallbackElement) {\n this.focusOn(fallbackElement);\n }\n };\n\n handleDateChange = (date: Date | null) => {\n this.setState(\n (state) => {\n const originalDate = state.originalDate ?? this.props.value;\n return { originalDate };\n },\n () => {\n this.props.onChange(date);\n },\n );\n };\n\n handleDateSelect = (date: Date) => {\n this.props.onChange(date);\n this.close();\n this.focusOn('.btn');\n };\n\n getCalendar = () => {\n const { value, min, max, monthFormat, placeholder } = this.props;\n return (\n <div className=\"p-a-1\">\n <Calendar\n value={value}\n min={min}\n max={max}\n monthFormat={monthFormat}\n placeholder={placeholder}\n onChange={this.handleDateChange}\n onSelect={this.handleDateSelect}\n />\n </div>\n );\n };\n\n handleClear = () => {\n this.props.onChange(null);\n this.focusOn('.np-date-trigger');\n };\n\n render() {\n const { open } = this.state;\n\n const {\n inputAttributes,\n id: idProp,\n 'aria-labelledby': ariaLabelledByProp,\n size,\n placeholder,\n label,\n monthFormat,\n disabled,\n clearable,\n value,\n } = this.props;\n const id = idProp ?? inputAttributes?.id;\n const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes?.['aria-labelledby'];\n\n return (\n <div\n ref={this.element}\n aria-labelledby={id}\n aria-invalid={inputAttributes?.['aria-invalid']}\n aria-describedby={inputAttributes?.['aria-describedby']}\n className={clsx('input-group', disabled && 'disabled')}\n onKeyDown={this.handleKeyDown}\n >\n <OverlayIdProvider open={open}>\n <DateTrigger\n id={id}\n ariaLabelledBy={ariaLabelledBy}\n selectedDate={value}\n size={size}\n placeholder={placeholder}\n label={label}\n monthFormat={monthFormat}\n disabled={disabled || false}\n onClick={this.open}\n onClear={!disabled && clearable && value ? this.handleClear : undefined}\n />\n <ResponsivePanel\n anchorRef={this.element}\n open={open}\n className=\"tw-date-lookup-menu\"\n position={Position.BOTTOM}\n considerHeight\n onClose={this.discard}\n >\n {this.getCalendar()}\n </ResponsivePanel>\n </OverlayIdProvider>\n </div>\n );\n }\n}\n\nexport const DateLookupWithoutInputAttributes = DateLookup;\n\nconst WrappedDateLookup = withInputAttributes(\n DateLookup as React.ComponentType<DateLookupPropsWithInputAttributes>,\n { nonLabelable: true },\n);\nWrappedDateLookup.displayName = 'DateLookup';\n\nexport default WrappedDateLookup;\n"],"names":["DateLookup","PureComponent","defaultProps","value","min","max","size","Size","MEDIUM","placeholder","label","monthFormat","MonthFormat","LONG","disabled","clearable","element","createRef","constructor","props","state","originalDate","open","componentDidUpdate","previousProps","getTime","focusOn","onFocus","setState","discard","onChange","close","onBlur","handleKeyDown","event","key","preventDefault","preferredElement","fallbackElement","current","querySelector","focus","handleDateChange","date","handleDateSelect","getCalendar","_jsx","className","children","Calendar","onSelect","handleClear","render","inputAttributes","id","idProp","ariaLabelledByProp","ariaLabelledBy","ref","clsx","onKeyDown","_jsxs","OverlayIdProvider","DateTrigger","selectedDate","onClick","onClear","undefined","ResponsivePanel","anchorRef","position","Position","BOTTOM","considerHeight","onClose","WrappedDateLookup","withInputAttributes","nonLabelable","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAMA,UAAW,SAAQC,mBAAkE,CAAA;AAIzF,EAAA,OAAOC,YAAY,GAAG;AACpBC,IAAAA,KAAK,EAAE,IAAI;AACXC,IAAAA,GAAG,EAAE,IAAI;AACTC,IAAAA,GAAG,EAAE,IAAI;IACTC,IAAI,EAAEC,SAAI,CAACC,MAAM;AACjBC,IAAAA,WAAW,EAAE,EAAE;AACfC,IAAAA,KAAK,EAAE,EAAE;IACTC,WAAW,EAAEC,uBAAW,CAACC,IAAI;AAC7BC,IAAAA,QAAQ,EAAE,KAAK;AACfC,IAAAA,SAAS,EAAE;GAC0C;EAEvDC,OAAO,gBAAGC,eAAS,EAAkB;EAErCC,WAAAA,CAAYC,KAA0B,EAAA;IACpC,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,YAAY,EAAE,IAAI;AAClBC,MAAAA,IAAI,EAAE;KACP;AACH,EAAA;EAEAC,kBAAkBA,CAACC,aAAiD,EAAA;IAClE,IAAI,IAAI,CAACL,KAAK,CAAChB,KAAK,EAAEsB,OAAO,EAAE,KAAKD,aAAa,CAACrB,KAAK,EAAEsB,OAAO,EAAE,IAAI,IAAI,CAACL,KAAK,CAACE,IAAI,EAAE;AACrF,MAAA,IAAI,CAACI,OAAO,CAAC,SAAS,CAAC;AACzB,IAAA;AACF,EAAA;EAEAJ,IAAI,GAAGA,MAAK;IACV,MAAM;AAAEK,MAAAA;KAAS,GAAG,IAAI,CAACR,KAAK;IAE9B,IAAI,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,EAAEA,cAAe;AAC/BO,UAAAA,YAAY,EAAE7D,KAAM;AACpBG,UAAAA,IAAI,EAAEA,IAAK;AACXG,UAAAA,WAAW,EAAEA,WAAY;AACzBC,UAAAA,KAAK,EAAEA,KAAM;AACbC,UAAAA,WAAW,EAAEA,WAAY;UACzBG,QAAQ,EAAEA,QAAQ,IAAI,KAAM;UAC5BmD,OAAO,EAAE,IAAI,CAAC3C,IAAK;UACnB4C,OAAO,EAAE,CAACpD,QAAQ,IAAIC,SAAS,IAAIZ,KAAK,GAAG,IAAI,CAACgD,WAAW,GAAGgB;AAAU,SAAA,CAE1E,eAAArB,cAAA,CAACsB,uBAAe,EAAA;UACdC,SAAS,EAAE,IAAI,CAACrD,OAAQ;AACxBM,UAAAA,IAAI,EAAEA,IAAK;AACXyB,UAAAA,SAAS,EAAC,qBAAqB;UAC/BuB,QAAQ,EAAEC,iBAAQ,CAACC,MAAO;UAC1BC,cAAc,EAAA,IAAA;UACdC,OAAO,EAAE,IAAI,CAAC7C,OAAQ;AAAAmB,UAAAA,QAAA,EAErB,IAAI,CAACH,WAAW;AAAE,SACJ,CACnB;OAAmB;AACrB,KAAK,CAAC;AAEV,EAAA;;AAKF,MAAM8B,iBAAiB,GAAGC,4BAAmB,CAC3C5E,UAAqE,EACrE;AAAE6E,EAAAA,YAAY,EAAE;AAAI,CAAE;AAExBF,iBAAiB,CAACG,WAAW,GAAG,YAAY;;;;"}
|
|
@@ -119,19 +119,7 @@ class DateLookup extends PureComponent {
|
|
|
119
119
|
this.focusOn(fallbackElement);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
handleDateChange =
|
|
123
|
-
const {
|
|
124
|
-
onDateSelect
|
|
125
|
-
} = this.props;
|
|
126
|
-
if (date && onDateSelect) {
|
|
127
|
-
onDateSelect({
|
|
128
|
-
date,
|
|
129
|
-
isEnabled: meta.isEnabled
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
handleDateSelect = date => {
|
|
134
|
-
if (!date) return;
|
|
122
|
+
handleDateChange = date => {
|
|
135
123
|
this.setState(state => {
|
|
136
124
|
const originalDate = state.originalDate ?? this.props.value;
|
|
137
125
|
return {
|
|
@@ -139,18 +127,20 @@ class DateLookup extends PureComponent {
|
|
|
139
127
|
};
|
|
140
128
|
}, () => {
|
|
141
129
|
this.props.onChange(date);
|
|
142
|
-
this.close();
|
|
143
|
-
this.focusOn('.btn');
|
|
144
130
|
});
|
|
145
131
|
};
|
|
132
|
+
handleDateSelect = date => {
|
|
133
|
+
this.props.onChange(date);
|
|
134
|
+
this.close();
|
|
135
|
+
this.focusOn('.btn');
|
|
136
|
+
};
|
|
146
137
|
getCalendar = () => {
|
|
147
138
|
const {
|
|
148
139
|
value,
|
|
149
140
|
min,
|
|
150
141
|
max,
|
|
151
142
|
monthFormat,
|
|
152
|
-
placeholder
|
|
153
|
-
disabledRules
|
|
143
|
+
placeholder
|
|
154
144
|
} = this.props;
|
|
155
145
|
return /*#__PURE__*/jsx("div", {
|
|
156
146
|
className: "p-a-1",
|
|
@@ -160,9 +150,8 @@ class DateLookup extends PureComponent {
|
|
|
160
150
|
max: max,
|
|
161
151
|
monthFormat: monthFormat,
|
|
162
152
|
placeholder: placeholder,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
onChange: this.handleDateSelect
|
|
153
|
+
onChange: this.handleDateChange,
|
|
154
|
+
onSelect: this.handleDateSelect
|
|
166
155
|
})
|
|
167
156
|
});
|
|
168
157
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateLookup.mjs","sources":["../../src/DateLookup/DateLookup.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, PureComponent, KeyboardEvent } from 'react';\nimport Calendar from '../Calendar';\nimport type { DateChangeMeta, DisabledRules, OnDateSelectParams } from '../Calendar/Calendar.types';\nimport {\n Size,\n MonthFormat,\n Position,\n type SizeSmall,\n type SizeMedium,\n type SizeLarge,\n} from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport { WithInputAttributesProps, withInputAttributes } from '../Inputs/contexts';\nimport { OverlayIdProvider } from '../Provider/overlay/OverlayIdProvider';\nimport DateTrigger from './DateTrigger';\n\nexport interface DateLookupProps {\n /** The currently selected date, or `null` for no selection. */\n value: Date | null;\n /** Called when an enabled date is confirmed. Receives `null` when the value is cleared. */\n onChange: (date: Date | null) => void;\n /** HTML `id` applied to the trigger button, used for label association. */\n id?: string;\n /** Earliest selectable date (inclusive). Dates before this are interactive but not selectable, and show a boundary prompt. */\n min?: Date | null;\n /** Latest selectable date (inclusive). Dates after this are interactive but not selectable, and show a boundary prompt. */\n max?: Date | null;\n /** Size of the trigger input. Defaults to `'md'`. */\n size?: SizeSmall | SizeMedium | SizeLarge;\n /** Label text rendered above the trigger input. */\n label?: string;\n /** ID of an external element that labels the trigger, for use inside custom label contexts. */\n 'aria-labelledby'?: string;\n /** Placeholder text shown in the trigger when no date is selected. */\n placeholder?: string;\n /** Month name format in the calendar header. Defaults to `'long'` (e.g. \"January\"). */\n monthFormat?: `${MonthFormat}`;\n /** When `true`, the trigger and calendar are non-interactive. */\n disabled?: boolean;\n /** When `true`, a clear button is shown in the trigger to reset the value to `null`. */\n clearable?: boolean;\n /** Rules for disabling specific weekdays, individual dates, or date ranges. The required `reason` is shown in an inline prompt and linked to disabled cells via `aria-describedby` for screen reader accessibility. */\n disabledRules?: DisabledRules;\n /** Called whenever any date is focused or clicked, including disabled and out-of-range dates. `isEnabled` is `false` when the date is not selectable. */\n onDateSelect?: (params: OnDateSelectParams) => void;\n /** Called when the calendar panel opens. */\n onFocus?: () => void;\n /** Called when the calendar panel closes. */\n onBlur?: () => void;\n}\n\ntype DateLookupPropsWithInputAttributes = DateLookupProps & Partial<WithInputAttributesProps>;\n\ninterface DateLookupState {\n originalDate: Date | null;\n open: boolean;\n}\n\nclass DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateLookupState> {\n declare props: DateLookupPropsWithInputAttributes &\n Required<Pick<DateLookupPropsWithInputAttributes, keyof typeof DateLookup.defaultProps>>;\n\n static defaultProps = {\n value: null,\n min: null,\n max: null,\n size: Size.MEDIUM,\n placeholder: '',\n label: '',\n monthFormat: MonthFormat.LONG,\n disabled: false,\n clearable: false,\n } satisfies Partial<DateLookupPropsWithInputAttributes>;\n\n element = createRef<HTMLDivElement>();\n\n constructor(props: DateLookup['props']) {\n super(props);\n this.state = {\n originalDate: null,\n open: false,\n };\n }\n\n componentDidUpdate(previousProps: DateLookupPropsWithInputAttributes) {\n if (this.props.value?.getTime() !== previousProps.value?.getTime() && this.state.open) {\n this.focusOn('.active');\n }\n }\n\n open = () => {\n const { onFocus } = this.props;\n\n this.setState({ open: true });\n if (onFocus) {\n onFocus();\n }\n };\n\n discard = () => {\n const { originalDate } = this.state;\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n };\n\n close = () => {\n const { onBlur } = this.props;\n this.setState({ open: false, originalDate: null });\n if (onBlur) {\n onBlur();\n }\n };\n\n handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const { open, originalDate } = this.state;\n switch (event.key) {\n case 'ArrowLeft':\n case 'ArrowUp':\n case 'ArrowRight':\n case 'ArrowDown':\n if (!open) {\n this.open();\n event.preventDefault();\n }\n break;\n case 'Escape':\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n event.preventDefault();\n break;\n default:\n break;\n }\n };\n\n focusOn = (preferredElement: string, fallbackElement?: string) => {\n const element = this.element.current?.querySelector(preferredElement) as HTMLElement | null;\n if (element) {\n element.focus();\n } else if (fallbackElement) {\n this.focusOn(fallbackElement);\n }\n };\n\n handleDateChange = (date: Date | null, meta: DateChangeMeta) => {\n const { onDateSelect } = this.props;\n if (date && onDateSelect) {\n onDateSelect({ date, isEnabled: meta.isEnabled });\n }\n };\n\n handleDateSelect = (date: Date | null) => {\n if (!date) return;\n this.setState(\n (state) => {\n const originalDate = state.originalDate ?? this.props.value;\n return { originalDate };\n },\n () => {\n this.props.onChange(date);\n this.close();\n this.focusOn('.btn');\n },\n );\n };\n\n getCalendar = () => {\n const { value, min, max, monthFormat, placeholder, disabledRules } = this.props;\n return (\n <div className=\"p-a-1\">\n <Calendar\n value={value}\n min={min}\n max={max}\n monthFormat={monthFormat}\n placeholder={placeholder}\n disabledRules={disabledRules}\n onDateFocus={this.handleDateChange}\n onChange={this.handleDateSelect}\n />\n </div>\n );\n };\n\n handleClear = () => {\n this.props.onChange(null);\n this.focusOn('.np-date-trigger');\n };\n\n render() {\n const { open } = this.state;\n\n const {\n inputAttributes,\n id: idProp,\n 'aria-labelledby': ariaLabelledByProp,\n size,\n placeholder,\n label,\n monthFormat,\n disabled,\n clearable,\n value,\n } = this.props;\n const id = idProp ?? inputAttributes?.id;\n const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes?.['aria-labelledby'];\n\n return (\n <div\n ref={this.element}\n aria-labelledby={id}\n aria-invalid={inputAttributes?.['aria-invalid']}\n aria-describedby={inputAttributes?.['aria-describedby']}\n className={clsx('input-group', disabled && 'disabled')}\n onKeyDown={this.handleKeyDown}\n >\n <OverlayIdProvider open={open}>\n <DateTrigger\n id={id}\n ariaLabelledBy={ariaLabelledBy}\n selectedDate={value}\n size={size}\n placeholder={placeholder}\n label={label}\n monthFormat={monthFormat}\n disabled={disabled || false}\n onClick={this.open}\n onClear={!disabled && clearable && value ? this.handleClear : undefined}\n />\n <ResponsivePanel\n anchorRef={this.element}\n open={open}\n className=\"tw-date-lookup-menu\"\n position={Position.BOTTOM}\n considerHeight\n onClose={this.discard}\n >\n {this.getCalendar()}\n </ResponsivePanel>\n </OverlayIdProvider>\n </div>\n );\n }\n}\n\nexport const DateLookupWithoutInputAttributes = DateLookup;\n\nconst WrappedDateLookup = withInputAttributes(\n DateLookup as React.ComponentType<DateLookupPropsWithInputAttributes>,\n { nonLabelable: true },\n);\nWrappedDateLookup.displayName = 'DateLookup';\n\nexport default WrappedDateLookup;\n"],"names":["DateLookup","PureComponent","defaultProps","value","min","max","size","Size","MEDIUM","placeholder","label","monthFormat","MonthFormat","LONG","disabled","clearable","element","createRef","constructor","props","state","originalDate","open","componentDidUpdate","previousProps","getTime","focusOn","onFocus","setState","discard","onChange","close","onBlur","handleKeyDown","event","key","preventDefault","preferredElement","fallbackElement","current","querySelector","focus","handleDateChange","date","meta","onDateSelect","isEnabled","handleDateSelect","getCalendar","disabledRules","_jsx","className","children","Calendar","onDateFocus","handleClear","render","inputAttributes","id","idProp","ariaLabelledByProp","ariaLabelledBy","ref","clsx","onKeyDown","_jsxs","OverlayIdProvider","DateTrigger","selectedDate","onClick","onClear","undefined","ResponsivePanel","anchorRef","position","Position","BOTTOM","considerHeight","onClose","WrappedDateLookup","withInputAttributes","nonLabelable","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,MAAMA,UAAW,SAAQC,aAAkE,CAAA;AAIzF,EAAA,OAAOC,YAAY,GAAG;AACpBC,IAAAA,KAAK,EAAE,IAAI;AACXC,IAAAA,GAAG,EAAE,IAAI;AACTC,IAAAA,GAAG,EAAE,IAAI;IACTC,IAAI,EAAEC,IAAI,CAACC,MAAM;AACjBC,IAAAA,WAAW,EAAE,EAAE;AACfC,IAAAA,KAAK,EAAE,EAAE;IACTC,WAAW,EAAEC,WAAW,CAACC,IAAI;AAC7BC,IAAAA,QAAQ,EAAE,KAAK;AACfC,IAAAA,SAAS,EAAE;GAC0C;EAEvDC,OAAO,gBAAGC,SAAS,EAAkB;EAErCC,WAAAA,CAAYC,KAA0B,EAAA;IACpC,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,YAAY,EAAE,IAAI;AAClBC,MAAAA,IAAI,EAAE;KACP;AACH,EAAA;EAEAC,kBAAkBA,CAACC,aAAiD,EAAA;IAClE,IAAI,IAAI,CAACL,KAAK,CAAChB,KAAK,EAAEsB,OAAO,EAAE,KAAKD,aAAa,CAACrB,KAAK,EAAEsB,OAAO,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BAAmB,CAC3ChF,UAAqE,EACrE;AAAEiF,EAAAA,YAAY,EAAE;AAAI,CAAE;AAExBF,iBAAiB,CAACG,WAAW,GAAG,YAAY;;;;"}
|
|
1
|
+
{"version":3,"file":"DateLookup.mjs","sources":["../../src/DateLookup/DateLookup.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, PureComponent, KeyboardEvent } from 'react';\nimport Calendar from '../Calendar';\nimport {\n Size,\n MonthFormat,\n Position,\n type SizeSmall,\n type SizeMedium,\n type SizeLarge,\n} from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport { WithInputAttributesProps, withInputAttributes } from '../Inputs/contexts';\nimport { OverlayIdProvider } from '../Provider/overlay/OverlayIdProvider';\nimport DateTrigger from './DateTrigger';\n\nexport interface DateLookupProps {\n id?: string;\n value: Date | null;\n min?: Date | null;\n max?: Date | null;\n size?: SizeSmall | SizeMedium | SizeLarge;\n placeholder?: string;\n label?: string;\n 'aria-labelledby'?: string;\n monthFormat?: `${MonthFormat}`;\n disabled?: boolean;\n clearable?: boolean;\n onChange: (date: Date | null) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n}\n\ntype DateLookupPropsWithInputAttributes = DateLookupProps & Partial<WithInputAttributesProps>;\n\ninterface DateLookupState {\n originalDate: Date | null;\n open: boolean;\n}\n\nclass DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateLookupState> {\n declare props: DateLookupPropsWithInputAttributes &\n Required<Pick<DateLookupPropsWithInputAttributes, keyof typeof DateLookup.defaultProps>>;\n\n static defaultProps = {\n value: null,\n min: null,\n max: null,\n size: Size.MEDIUM,\n placeholder: '',\n label: '',\n monthFormat: MonthFormat.LONG,\n disabled: false,\n clearable: false,\n } satisfies Partial<DateLookupPropsWithInputAttributes>;\n\n element = createRef<HTMLDivElement>();\n\n constructor(props: DateLookup['props']) {\n super(props);\n this.state = {\n originalDate: null,\n open: false,\n };\n }\n\n componentDidUpdate(previousProps: DateLookupPropsWithInputAttributes) {\n if (this.props.value?.getTime() !== previousProps.value?.getTime() && this.state.open) {\n this.focusOn('.active');\n }\n }\n\n open = () => {\n const { onFocus } = this.props;\n\n this.setState({ open: true });\n if (onFocus) {\n onFocus();\n }\n };\n\n discard = () => {\n const { originalDate } = this.state;\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n };\n\n close = () => {\n const { onBlur } = this.props;\n this.setState({ open: false, originalDate: null });\n if (onBlur) {\n onBlur();\n }\n };\n\n handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const { open, originalDate } = this.state;\n switch (event.key) {\n case 'ArrowLeft':\n case 'ArrowUp':\n case 'ArrowRight':\n case 'ArrowDown':\n if (!open) {\n this.open();\n event.preventDefault();\n }\n break;\n case 'Escape':\n if (originalDate !== null) {\n this.props.onChange(originalDate);\n }\n this.close();\n event.preventDefault();\n break;\n default:\n break;\n }\n };\n\n focusOn = (preferredElement: string, fallbackElement?: string) => {\n const element = this.element.current?.querySelector(preferredElement) as HTMLElement | null;\n if (element) {\n element.focus();\n } else if (fallbackElement) {\n this.focusOn(fallbackElement);\n }\n };\n\n handleDateChange = (date: Date | null) => {\n this.setState(\n (state) => {\n const originalDate = state.originalDate ?? this.props.value;\n return { originalDate };\n },\n () => {\n this.props.onChange(date);\n },\n );\n };\n\n handleDateSelect = (date: Date) => {\n this.props.onChange(date);\n this.close();\n this.focusOn('.btn');\n };\n\n getCalendar = () => {\n const { value, min, max, monthFormat, placeholder } = this.props;\n return (\n <div className=\"p-a-1\">\n <Calendar\n value={value}\n min={min}\n max={max}\n monthFormat={monthFormat}\n placeholder={placeholder}\n onChange={this.handleDateChange}\n onSelect={this.handleDateSelect}\n />\n </div>\n );\n };\n\n handleClear = () => {\n this.props.onChange(null);\n this.focusOn('.np-date-trigger');\n };\n\n render() {\n const { open } = this.state;\n\n const {\n inputAttributes,\n id: idProp,\n 'aria-labelledby': ariaLabelledByProp,\n size,\n placeholder,\n label,\n monthFormat,\n disabled,\n clearable,\n value,\n } = this.props;\n const id = idProp ?? inputAttributes?.id;\n const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes?.['aria-labelledby'];\n\n return (\n <div\n ref={this.element}\n aria-labelledby={id}\n aria-invalid={inputAttributes?.['aria-invalid']}\n aria-describedby={inputAttributes?.['aria-describedby']}\n className={clsx('input-group', disabled && 'disabled')}\n onKeyDown={this.handleKeyDown}\n >\n <OverlayIdProvider open={open}>\n <DateTrigger\n id={id}\n ariaLabelledBy={ariaLabelledBy}\n selectedDate={value}\n size={size}\n placeholder={placeholder}\n label={label}\n monthFormat={monthFormat}\n disabled={disabled || false}\n onClick={this.open}\n onClear={!disabled && clearable && value ? this.handleClear : undefined}\n />\n <ResponsivePanel\n anchorRef={this.element}\n open={open}\n className=\"tw-date-lookup-menu\"\n position={Position.BOTTOM}\n considerHeight\n onClose={this.discard}\n >\n {this.getCalendar()}\n </ResponsivePanel>\n </OverlayIdProvider>\n </div>\n );\n }\n}\n\nexport const DateLookupWithoutInputAttributes = DateLookup;\n\nconst WrappedDateLookup = withInputAttributes(\n DateLookup as React.ComponentType<DateLookupPropsWithInputAttributes>,\n { nonLabelable: true },\n);\nWrappedDateLookup.displayName = 'DateLookup';\n\nexport default WrappedDateLookup;\n"],"names":["DateLookup","PureComponent","defaultProps","value","min","max","size","Size","MEDIUM","placeholder","label","monthFormat","MonthFormat","LONG","disabled","clearable","element","createRef","constructor","props","state","originalDate","open","componentDidUpdate","previousProps","getTime","focusOn","onFocus","setState","discard","onChange","close","onBlur","handleKeyDown","event","key","preventDefault","preferredElement","fallbackElement","current","querySelector","focus","handleDateChange","date","handleDateSelect","getCalendar","_jsx","className","children","Calendar","onSelect","handleClear","render","inputAttributes","id","idProp","ariaLabelledByProp","ariaLabelledBy","ref","clsx","onKeyDown","_jsxs","OverlayIdProvider","DateTrigger","selectedDate","onClick","onClear","undefined","ResponsivePanel","anchorRef","position","Position","BOTTOM","considerHeight","onClose","WrappedDateLookup","withInputAttributes","nonLabelable","displayName"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