no-frills-ui 0.0.14-alpha.8 → 0.0.14-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.js +847 -718
- package/dist/index.js.map +1 -1
- package/lib-esm/components/Accordion/Accordion.d.ts +9 -13
- package/lib-esm/components/Accordion/Accordion.js +13 -11
- package/lib-esm/components/Accordion/Accordion.js.map +1 -1
- package/lib-esm/components/Accordion/AccordionStep.d.ts +22 -22
- package/lib-esm/components/Accordion/AccordionStep.js +34 -29
- package/lib-esm/components/Accordion/AccordionStep.js.map +1 -1
- package/lib-esm/components/Badge/Badge.d.ts +13 -16
- package/lib-esm/components/Badge/Badge.js +10 -20
- package/lib-esm/components/Badge/Badge.js.map +1 -1
- package/lib-esm/components/Button/ActionButton.d.ts +9 -5
- package/lib-esm/components/Button/ActionButton.js +18 -3
- package/lib-esm/components/Button/ActionButton.js.map +1 -1
- package/lib-esm/components/Button/Button.d.ts +9 -5
- package/lib-esm/components/Button/Button.js +17 -5
- package/lib-esm/components/Button/Button.js.map +1 -1
- package/lib-esm/components/Button/IconButton.d.ts +9 -5
- package/lib-esm/components/Button/IconButton.js +18 -3
- package/lib-esm/components/Button/IconButton.js.map +1 -1
- package/lib-esm/components/Button/LinkButton.d.ts +9 -5
- package/lib-esm/components/Button/LinkButton.js +18 -3
- package/lib-esm/components/Button/LinkButton.js.map +1 -1
- package/lib-esm/components/Button/RaisedButton.d.ts +9 -5
- package/lib-esm/components/Button/RaisedButton.js +18 -3
- package/lib-esm/components/Button/RaisedButton.js.map +1 -1
- package/lib-esm/components/Card/Card.d.ts +4 -6
- package/lib-esm/components/Card/Card.js +16 -3
- package/lib-esm/components/Card/Card.js.map +1 -1
- package/lib-esm/components/Chip/Chip.d.ts +2 -2
- package/lib-esm/components/Chip/Chip.js +14 -8
- package/lib-esm/components/Chip/Chip.js.map +1 -1
- package/lib-esm/components/ChipInput/ChipInput.d.ts +28 -39
- package/lib-esm/components/ChipInput/ChipInput.js +37 -37
- package/lib-esm/components/ChipInput/ChipInput.js.map +1 -1
- package/lib-esm/components/Dialog/AlertDialog.d.ts +11 -12
- package/lib-esm/components/Dialog/AlertDialog.js +4 -11
- package/lib-esm/components/Dialog/AlertDialog.js.map +1 -1
- package/lib-esm/components/Dialog/ConfirmDialog.d.ts +13 -14
- package/lib-esm/components/Dialog/ConfirmDialog.js +4 -12
- package/lib-esm/components/Dialog/ConfirmDialog.js.map +1 -1
- package/lib-esm/components/Dialog/Dialog.d.ts +8 -14
- package/lib-esm/components/Dialog/Dialog.js +11 -9
- package/lib-esm/components/Dialog/Dialog.js.map +1 -1
- package/lib-esm/components/Dialog/PromptDialog.d.ts +18 -19
- package/lib-esm/components/Dialog/PromptDialog.js +10 -18
- package/lib-esm/components/Dialog/PromptDialog.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragAndDrop.d.ts +37 -59
- package/lib-esm/components/DragAndDrop/DragAndDrop.js +23 -26
- package/lib-esm/components/DragAndDrop/DragAndDrop.js.map +1 -1
- package/lib-esm/components/DragAndDrop/DragItem.d.ts +2 -2
- package/lib-esm/components/DragAndDrop/DragItem.js +40 -38
- package/lib-esm/components/DragAndDrop/DragItem.js.map +1 -1
- package/lib-esm/components/DragAndDrop/types.d.ts +3 -3
- package/lib-esm/components/DragAndDrop/types.js.map +1 -1
- package/lib-esm/components/Drawer/Drawer.d.ts +24 -31
- package/lib-esm/components/Drawer/Drawer.js +49 -45
- package/lib-esm/components/Drawer/Drawer.js.map +1 -1
- package/lib-esm/components/Groups/Group.d.ts +6 -8
- package/lib-esm/components/Groups/Group.js +12 -10
- package/lib-esm/components/Groups/Group.js.map +1 -1
- package/lib-esm/components/Input/Checkbox.d.ts +12 -15
- package/lib-esm/components/Input/Checkbox.js +30 -26
- package/lib-esm/components/Input/Checkbox.js.map +1 -1
- package/lib-esm/components/Input/Dropdown.d.ts +8 -18
- package/lib-esm/components/Input/Dropdown.js +42 -17
- package/lib-esm/components/Input/Dropdown.js.map +1 -1
- package/lib-esm/components/Input/Input.d.ts +8 -3
- package/lib-esm/components/Input/Input.js +20 -19
- package/lib-esm/components/Input/Input.js.map +1 -1
- package/lib-esm/components/Input/Radio.d.ts +4 -8
- package/lib-esm/components/Input/Radio.js +16 -13
- package/lib-esm/components/Input/Radio.js.map +1 -1
- package/lib-esm/components/Input/RadioButton.d.ts +4 -8
- package/lib-esm/components/Input/RadioButton.js +15 -12
- package/lib-esm/components/Input/RadioButton.js.map +1 -1
- package/lib-esm/components/Input/Select.d.ts +6 -13
- package/lib-esm/components/Input/Select.js +21 -18
- package/lib-esm/components/Input/Select.js.map +1 -1
- package/lib-esm/components/Input/TextArea.d.ts +6 -13
- package/lib-esm/components/Input/TextArea.js +29 -24
- package/lib-esm/components/Input/TextArea.js.map +1 -1
- package/lib-esm/components/Input/Toggle.d.ts +4 -9
- package/lib-esm/components/Input/Toggle.js +12 -10
- package/lib-esm/components/Input/Toggle.js.map +1 -1
- package/lib-esm/components/Menu/Menu.d.ts +4 -14
- package/lib-esm/components/Menu/Menu.js +24 -16
- package/lib-esm/components/Menu/Menu.js.map +1 -1
- package/lib-esm/components/Menu/MenuContext.d.ts +4 -4
- package/lib-esm/components/Menu/MenuContext.js +1 -0
- package/lib-esm/components/Menu/MenuContext.js.map +1 -1
- package/lib-esm/components/Menu/MenuItem.d.ts +10 -4
- package/lib-esm/components/Menu/MenuItem.js +19 -5
- package/lib-esm/components/Menu/MenuItem.js.map +1 -1
- package/lib-esm/components/Modal/Modal.d.ts +17 -23
- package/lib-esm/components/Modal/Modal.js +37 -34
- package/lib-esm/components/Modal/Modal.js.map +1 -1
- package/lib-esm/components/Notification/Notification.d.ts +39 -34
- package/lib-esm/components/Notification/Notification.js +16 -39
- package/lib-esm/components/Notification/Notification.js.map +1 -1
- package/lib-esm/components/Notification/NotificationManager.d.ts +4 -4
- package/lib-esm/components/Notification/NotificationManager.js +18 -14
- package/lib-esm/components/Notification/NotificationManager.js.map +1 -1
- package/lib-esm/components/Notification/index.d.ts +1 -0
- package/lib-esm/components/Notification/style.d.ts +2 -3
- package/lib-esm/components/Notification/style.js +11 -11
- package/lib-esm/components/Notification/style.js.map +1 -1
- package/lib-esm/components/Popover/Popover.d.ts +21 -20
- package/lib-esm/components/Popover/Popover.js +42 -44
- package/lib-esm/components/Popover/Popover.js.map +1 -1
- package/lib-esm/components/Spinner/Spinner.d.ts +14 -15
- package/lib-esm/components/Spinner/Spinner.js +12 -13
- package/lib-esm/components/Spinner/Spinner.js.map +1 -1
- package/lib-esm/components/Stepper/Step.d.ts +15 -12
- package/lib-esm/components/Stepper/Step.js +10 -8
- package/lib-esm/components/Stepper/Step.js.map +1 -1
- package/lib-esm/components/Stepper/Stepper.d.ts +11 -17
- package/lib-esm/components/Stepper/Stepper.js +25 -23
- package/lib-esm/components/Stepper/Stepper.js.map +1 -1
- package/lib-esm/components/Tabs/Tab.d.ts +10 -16
- package/lib-esm/components/Tabs/Tab.js +0 -8
- package/lib-esm/components/Tabs/Tab.js.map +1 -1
- package/lib-esm/components/Tabs/Tabs.d.ts +11 -22
- package/lib-esm/components/Tabs/Tabs.js +39 -31
- package/lib-esm/components/Tabs/Tabs.js.map +1 -1
- package/lib-esm/components/Toast/Toast.d.ts +7 -7
- package/lib-esm/components/Toast/Toast.js +13 -12
- package/lib-esm/components/Toast/Toast.js.map +1 -1
- package/lib-esm/components/Toast/ToastStory.d.ts +21 -24
- package/lib-esm/components/Tooltip/Tooltip.d.ts +11 -14
- package/lib-esm/components/Tooltip/Tooltip.js +11 -21
- package/lib-esm/components/Tooltip/Tooltip.js.map +1 -1
- package/lib-esm/icons/CheckCircle.js +2 -2
- package/lib-esm/icons/CheckCircle.js.map +1 -1
- package/lib-esm/icons/ErrorOutline.js +2 -2
- package/lib-esm/icons/ErrorOutline.js.map +1 -1
- package/lib-esm/icons/Info.js +2 -2
- package/lib-esm/icons/Info.js.map +1 -1
- package/lib-esm/icons/ReportProblem.js +2 -2
- package/lib-esm/icons/ReportProblem.js.map +1 -1
- package/lib-esm/index.js +43 -0
- package/lib-esm/shared/LayerManager.d.ts +5 -4
- package/lib-esm/shared/LayerManager.js +111 -111
- package/lib-esm/shared/LayerManager.js.map +1 -1
- package/lib-esm/shared/styles.d.ts +1 -1
- package/lib-esm/shared/styles.js +9 -9
- package/lib-esm/shared/styles.js.map +1 -1
- package/package.json +66 -31
- package/lib-esm/components/index.js +0 -43
- /package/lib-esm/{components/index.js.map → index.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChipInput.js","sources":["../../../src/components/ChipInput/ChipInput.tsx"],"sourcesContent":["import React, { useEffect, useId, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\nimport Chip from '../Chip/Chip';\nimport { DragAndDrop, ORIENTATION } from '../DragAndDrop';\n\n// Prop types definition\ntype ChipInputProps = PropTypes.InferProps<typeof ChipInput.propTypes>;\n\n// Label component for the ChipInput\nconst Label = styled.label<{\n text: string;\n touched?: boolean;\n errorText?: string;\n}>`\n display: inline-flex;\n flex-direction: column;\n flex: 1;\n position: relative;\n margin: 10px 5px;\n color: inherit;\n padding: 0 8px;\n width: 250px;\n border-radius: 3px;\n border: 1px solid ${getThemeValue(THEME_NAME.BORDER_COLOR)};\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n\n /** Focused */\n &:has(:focus),\n &:has(:active) {\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:has(:focus) > span,\n &:has(:active) > span {\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /** Disabled */\n &:has(:disabled) {\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n background-color: ${getThemeValue(THEME_NAME.DISABLED_BACKGROUND)};\n }\n\n &:has(:disabled) > span {\n color: ${getThemeValue(THEME_NAME.DISABLED)};\n }\n\n /** Invalid */\n &:has(:focus:invalid) {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.ERROR_LIGHT)};\n }\n\n ${(props) =>\n props.touched\n ? `\n &:has(:invalid) {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n \n &:has(:invalid) > span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Error */\n ${(props) =>\n props.errorText\n ? `\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n\n & > span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Required */\n &:has(:required) > span:after {\n content: '*';\n margin-left: 2px;\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n\n & > input {\n border: none;\n outline: none;\n line-height: 30px;\n min-height: 30px;\n max-width: 95%;\n }\n\n /** Label Animation */\n & > span {\n position: absolute;\n padding: 0 5px;\n top: 0px;\n left: 4px;\n font-size: 14px;\n line-height: 32px;\n transition: all 300ms ease;\n }\n\n &:has(:focus) > span,\n &:has(:placeholder-shown) > span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n\n ${(props) =>\n props.text !== ''\n ? `\n & > span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n `\n : ''}\n`;\n\n// Error message container\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n margin-left: 3px;\n`;\n\n// Visually hidden but accessible to screen readers\nconst VisuallyHidden = styled.ul`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border-width: 0;\n\n & li {\n list-style: none;\n }\n`;\n\n/**\n * A chip input component that allows users to add and remove chips (tags) by typing and pressing Enter.\n * @component\n * @example\n * ```tsx\n * <ChipInput\n * value={['tag1', 'tag2']}\n * onChange={(newTags) => console.log(newTags)}\n * label=\"Add tags\"\n * errorText=\"At least one tag is required\"\n * />\n * ```\n */\nexport default function ChipInput(\n props: ChipInputProps & React.AllHTMLAttributes<HTMLInputElement>,\n) {\n const [text, setText] = useState('');\n const [touched, setTouched] = useState(false);\n const [value, setValue] = useState<string[]>(props.value || []);\n const InputRef = React.useRef<HTMLInputElement>(null);\n const [announcement, setAnnouncement] = useState('');\n const errorId = useId();\n\n /**\n * Replace {:label} placeholder in template string\n */\n const replacePlaceholder = (\n template: string | undefined,\n label: string,\n ): string | undefined => {\n if (!template) return undefined;\n return template.replace(/\\{:label\\}/g, label);\n };\n\n // Sync internal value with props.value\n useEffect(() => {\n if (Array.isArray(props.value)) {\n setValue(props.value);\n }\n }, [props.value]);\n\n /**\n * Update the chip values and notify changes.\n * @param newValue The new array of chip values\n */\n const updateValue = (newValue: string[]) => {\n const deduped = Array.from(new Set(newValue));\n setValue(deduped);\n props.onChange?.(deduped);\n };\n\n /**\n * Marks the input as touched on focus.\n * @param e React focus event\n */\n const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n setTouched(true);\n if (props.onFocus) {\n props.onFocus(e);\n }\n };\n\n /**\n * Change handler for the input field.\n * @param e React change event\n */\n const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setText(e.target.value);\n };\n\n /**\n * Adds a new chip on Enter key press.\n * @param e React keyboard event\n */\n const handleKeyUp: React.KeyboardEventHandler<HTMLInputElement> = (e) => {\n if (e.key === 'Enter' && text.trim() !== '' && InputRef.current.validity.valid) {\n const newValue = [...value, text.trim()];\n updateValue(newValue);\n setText('');\n setAnnouncement(replacePlaceholder(props.addedAnnouncementTemplate, text.trim())!);\n }\n };\n\n /**\n * Removes a chip from the list.\n * @param chipToRemove The chip value to remove\n */\n const removeChip = (chipToRemove: string) => {\n const newValue = value.filter((chip) => chip !== chipToRemove);\n updateValue(newValue);\n setAnnouncement(replacePlaceholder(props.removedAnnouncementTemplate, chipToRemove)!);\n };\n\n /**\n * Moves a chip from one position to another.\n * @param start The starting index of the item to move\n * @param end The ending index where the item should be placed\n */\n const onDrop = (start: number, end: number) => {\n // Clone existing elements\n const newItems = [...value];\n // Remove the element to be moved\n const item = newItems.splice(start, 1);\n // Add it back at the required position\n newItems.splice(end, 0, item[0]);\n // Update\n updateValue(newItems);\n };\n\n // Render the component\n return (\n <>\n <Label text={text} touched={touched} errorText={props.errorText}>\n <input\n {...props}\n ref={InputRef}\n value={text}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyUp={handleKeyUp}\n required={props.required && value.length === 0}\n aria-required={props.required}\n aria-invalid={!!props.errorText}\n aria-describedby={props.errorText ? errorId : undefined}\n />\n <div>\n {value?.length > 0 && (\n <DragAndDrop orientation={ORIENTATION.HORIZONTAL} onDrop={onDrop}>\n {value.map((chip) => (\n <Chip\n key={chip}\n label={chip}\n onCloseClick={() => removeChip(chip)}\n closeButtonAriaLabel={replacePlaceholder(\n props.closeButtonAriaLabel,\n chip,\n )}\n />\n ))}\n </DragAndDrop>\n )}\n </div>\n <span>{props.label}</span>\n {props.errorText && <ErrorContainer id={errorId}>{props.errorText}</ErrorContainer>}\n </Label>\n <VisuallyHidden aria-live=\"polite\" aria-atomic=\"true\">\n {announcement}\n </VisuallyHidden>\n </>\n );\n}\n\nChipInput.propTypes = {\n /** Label for the field */\n label: PropTypes.string.isRequired,\n /** Error message for the field */\n errorText: PropTypes.string,\n /** Values to display as chips */\n value: PropTypes.arrayOf(PropTypes.string),\n /** Callback when chips change */\n onChange: PropTypes.func,\n /** Aria label for the close button on chip. Defaults to \"Remove {label}\" */\n closeButtonAriaLabel: PropTypes.string,\n /** Announcement text when a chip is added. Defaults to \"{label} was added\" */\n addedAnnouncementTemplate: PropTypes.string,\n /** Announcement text when a chip is removed. Defaults to \"{label} was removed\" */\n removedAnnouncementTemplate: PropTypes.string,\n};\n\nChipInput.defaultProps = {\n value: [],\n closeButtonAriaLabel: 'Remove {:label}',\n addedAnnouncementTemplate: '{:label} was added',\n removedAnnouncementTemplate: '{:label} was removed',\n};\n"],"names":["Label","styled","getThemeValue","THEME_NAME","BORDER_COLOR","BACKGROUND","PRIMARY","PRIMARY_LIGHT","DISABLED_BORDER","DISABLED_BACKGROUND","DISABLED","ERROR","ERROR_LIGHT","props","touched","errorText","text","ErrorContainer","VisuallyHidden","ChipInput","setText","useState","setTouched","value","setValue","InputRef","React","useRef","announcement","setAnnouncement","errorId","useId","replacePlaceholder","template","label","undefined","replace","useEffect","Array","isArray","updateValue","newValue","deduped","from","Set","onChange","handleFocus","e","onFocus","handleChange","target","handleKeyUp","key","trim","current","validity","valid","addedAnnouncementTemplate","removeChip","chipToRemove","filter","chip","removedAnnouncementTemplate","onDrop","start","end","newItems","item","splice","_jsxs","_Fragment","_jsx","input","ref","onKeyUp","required","length","aria-required","aria-invalid","aria-describedby","div","DragAndDrop","orientation","ORIENTATION","HORIZONTAL","map","Chip","onCloseClick","closeButtonAriaLabel","span","id","aria-live","aria-atomic","propTypes","PropTypes","string","isRequired","arrayOf","func","defaultProps"],"mappings":";;;;;;;;;AAUA;AACA,MAAMA,KAAAA,iBAAQC,MAAAA,CAAAA,OAAAA,EAAAA;;;qKAcUC,aAAAA,CAAcC,UAAAA,CAAWC,YAAY,CAAA,EAAA,oBAAA,EACrCF,aAAAA,CAAcC,WAAWE,UAAU,CAAA,EAAA,6CAAA,EAKnCH,cAAcC,UAAAA,CAAWG,OAAO,6BACxBJ,aAAAA,CAAcC,UAAAA,CAAWI,aAAa,CAAA,EAAA,qDAAA,EAKrDL,aAAAA,CAAcC,WAAWG,OAAO,CAAA,EAAA,kCAAA,EAKzBJ,cAAcC,UAAAA,CAAWK,eAAe,yBACpCN,aAAAA,CAAcC,UAAAA,CAAWM,mBAAmB,CAAA,EAAA,kCAAA,EAIvDP,aAAAA,CAAcC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AAA,CAClBnB,KAAAA,CAAM2E,oBAAoB,EAC1B3B,IAAAA;AALCA,iCAAAA,EAAAA,IAAAA,CAAAA;;;kCAYzBU,GAAA,CAACkB,MAAAA,EAAAA;AAAM5E,wBAAAA,QAAAA,EAAAA,KAAAA,CAAMqB;;oBACZrB,KAAAA,CAAME,SAAS,kBAAIwD,GAAA,CAACtD,cAAAA,EAAAA;wBAAeyE,EAAAA,EAAI5D,OAAAA;AAAUjB,wBAAAA,QAAAA,EAAAA,KAAAA,CAAME;;;;0BAE5DwD,GAAA,CAACrD,cAAAA,EAAAA;gBAAeyE,WAAAA,EAAU,QAAA;gBAASC,aAAAA,EAAY,MAAA;AAC1ChE,gBAAAA,QAAAA,EAAAA;;;;AAIjB;AAEAT,SAAAA,CAAU0E,SAAS,GAAG;AAClB,+BACA3D,KAAAA,EAAO4D,SAAAA,CAAUC,MAAM,CAACC,UAAU;uCAElCjF,SAAAA,EAAW+E,SAAAA,CAAUC,MAAM;AAC3B,sCACAxE,KAAAA,EAAOuE,SAAAA,CAAUG,OAAO,CAACH,UAAUC,MAAM,CAAA;sCAEzClD,QAAAA,EAAUiD,SAAAA,CAAUI,IAAI;iFAExBV,oBAAAA,EAAsBM,SAAAA,CAAUC,MAAM;mFAEtCtC,yBAAAA,EAA2BqC,SAAAA,CAAUC,MAAM;uFAE3CjC,2BAAAA,EAA6BgC,SAAAA,CAAUC;AAC3C,CAAA;AAEA5E,SAAAA,CAAUgF,YAAY,GAAG;AACrB5E,IAAAA,KAAAA,EAAO,EAAE;IACTiE,oBAAAA,EAAsB,iBAAA;IACtB/B,yBAAAA,EAA2B,oBAAA;IAC3BK,2BAAAA,EAA6B;AACjC,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"ChipInput.js","sources":["../../../src/components/ChipInput/ChipInput.tsx"],"sourcesContent":["import React, { useImperativeHandle, useEffect, useId, useState } from 'react';\nimport styled from '@emotion/styled';\nimport { getThemeValue, THEME_NAME } from '../../shared/constants';\nimport Chip from '../Chip/Chip';\nimport { DragAndDrop, ORIENTATION } from '../DragAndDrop';\n\n// Prop types definition\ninterface ChipInputProps {\n /** Label for the field */\n label: string;\n /** Error message for the field */\n errorText?: string;\n /**\n * Values to display as chips\n * @default []\n */\n value?: string[];\n /** Callback when chips change */\n onChange?: (newValue: string[]) => void;\n /**\n * Aria label for the close button on chip. Defaults to \"Remove {:label}\"\n * @default \"Remove {:label}\"\n */\n closeButtonAriaLabel?: string;\n /**\n * Announcement text when a chip is added. Defaults to \"{:label} was added\"\n * @default \"{:label} was added\"\n */\n addedAnnouncementTemplate?: string;\n /**\n * Announcement text when a chip is removed. Defaults to \"{:label} was removed\"\n * @default \"{:label} was removed\"\n */\n removedAnnouncementTemplate?: string;\n}\n\n// Label component for the ChipInput\nconst Label = styled.label<{\n text: string;\n touched?: boolean;\n errorText?: string;\n required?: boolean;\n width?: string | number;\n}>`\n display: inline-flex;\n flex-direction: column;\n flex: 1;\n position: relative;\n margin: 10px 5px;\n color: inherit;\n padding: 0 8px;\n border-radius: 3px;\n border: 1px solid ${getThemeValue(THEME_NAME.BORDER_COLOR)};\n background-color: ${getThemeValue(THEME_NAME.BACKGROUND)};\n width: ${(props) =>\n typeof props.width === 'number' ? `${props.width}px` : props.width || '250px'};\n max-width: 100%;\n\n /** Focused */\n &:has(:focus),\n &:has(:active) {\n border-color: ${getThemeValue(THEME_NAME.PRIMARY)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.PRIMARY_LIGHT)};\n }\n\n &:has(:focus) > span,\n &:has(:active) > span {\n color: ${getThemeValue(THEME_NAME.PRIMARY)};\n }\n\n /** Disabled */\n &:has(:disabled) {\n border-color: ${getThemeValue(THEME_NAME.DISABLED_BORDER)};\n background-color: ${getThemeValue(THEME_NAME.DISABLED_BACKGROUND)};\n }\n\n &:has(:disabled) > span {\n color: ${getThemeValue(THEME_NAME.DISABLED)};\n }\n\n /** Invalid */\n &:has(:focus:invalid) {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n box-shadow: 0 0 0 4px ${getThemeValue(THEME_NAME.ERROR_LIGHT)};\n }\n\n ${(props) =>\n props.touched\n ? `\n &:has(:invalid) {\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n \n &:has(:invalid) > span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Error */\n ${(props) =>\n props.errorText\n ? `\n border-color: ${getThemeValue(THEME_NAME.ERROR)};\n\n & > span {\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }\n `\n : ''}\n\n /** Required */\n ${(props) =>\n props.required\n ? `& > span:after {\n content: '*';\n margin-left: 2px;\n color: ${getThemeValue(THEME_NAME.ERROR)};\n }`\n : ''}\n \n\n & > input {\n border: none;\n outline: none;\n line-height: 30px;\n min-height: 30px;\n max-width: 95%;\n }\n\n /** Label Animation */\n & > span {\n position: absolute;\n padding: 0 5px;\n top: 0px;\n left: 4px;\n font-size: 14px;\n line-height: 32px;\n transition: all 300ms ease;\n }\n\n &:has(:focus) > span,\n &:has(:placeholder-shown) > span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n\n ${(props) =>\n props.text !== ''\n ? `\n & > span {\n top: -8px;\n background: ${getThemeValue(THEME_NAME.BACKGROUND)};\n font-size: 12px;\n line-height: 14px;\n }\n `\n : ''}\n`;\n\n// Error message container\nconst ErrorContainer = styled.div`\n color: ${getThemeValue(THEME_NAME.ERROR)};\n padding-top: 3px;\n font-size: 12px;\n line-height: 14px;\n margin-left: 3px;\n`;\n\n// Visually hidden but accessible to screen readers\nconst VisuallyHidden = styled.ul`\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border-width: 0;\n\n & li {\n list-style: none;\n }\n`;\n\n/**\n * A chip input component that allows users to add and remove chips (tags) by typing and pressing Enter.\n * @component\n * @example\n * ```tsx\n * <ChipInput\n * value={['tag1', 'tag2']}\n * onChange={(newTags) => console.log(newTags)}\n * label=\"Add tags\"\n * errorText=\"At least one tag is required\"\n * />\n * ```\n */\nfunction ChipInputComponent(\n props: ChipInputProps & Omit<React.AllHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'>,\n ref: React.Ref<HTMLInputElement | null>,\n) {\n const {\n value: propValue = [],\n closeButtonAriaLabel = `Remove {:label}`,\n addedAnnouncementTemplate = '{:label} was added',\n removedAnnouncementTemplate = '{:label} was removed',\n } = props;\n\n const [text, setText] = useState('');\n const [touched, setTouched] = useState(false);\n const [value, setValue] = useState<string[]>(propValue || []);\n const InputRef = React.useRef<HTMLInputElement>(null);\n const [announcement, setAnnouncement] = useState('');\n const errorId = useId();\n\n // Forward the underlying input element.\n useImperativeHandle(ref, () => InputRef.current as HTMLInputElement);\n\n /**\n * Replace {:label} placeholder in template string\n */\n const replacePlaceholder = (\n template: string | undefined,\n label: string,\n ): string | undefined => {\n if (!template) return undefined;\n return template.replace(/\\{:label\\}/g, label);\n };\n\n const prevPropValueRef = React.useRef<string[]>(undefined);\n\n // Sync internal value with props.value\n useEffect(() => {\n if (Array.isArray(propValue)) {\n const prevValue = prevPropValueRef.current;\n const isEqual =\n prevValue &&\n propValue.length === prevValue.length &&\n propValue.every((val, index) => val === prevValue[index]);\n if (!isEqual) {\n setValue(propValue);\n prevPropValueRef.current = propValue;\n }\n }\n }, [propValue]);\n\n /**\n * Update the chip values and notify changes.\n * @param newValue The new array of chip values\n */\n const updateValue = (newValue: string[]) => {\n const deduped = Array.from(new Set(newValue));\n setValue(deduped);\n props.onChange?.(deduped);\n };\n\n /**\n * Marks the input as touched on focus.\n * @param e React focus event\n */\n const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n setTouched(true);\n if (props.onFocus) {\n props.onFocus(e);\n }\n };\n\n /**\n * Change handler for the input field.\n * @param e React change event\n */\n const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setText(e.target.value);\n };\n\n /**\n * Adds a new chip on Enter key press.\n * @param e React keyboard event\n */\n const handleKeyUp: React.KeyboardEventHandler<HTMLInputElement> = (e) => {\n if (e.key === 'Enter' && text.trim() !== '' && InputRef.current?.validity.valid) {\n const newValue = [...value, text.trim()];\n updateValue(newValue);\n setText('');\n setAnnouncement(replacePlaceholder(addedAnnouncementTemplate, text.trim())!);\n }\n };\n\n /**\n * Removes a chip from the list.\n * @param chipToRemove The chip value to remove\n */\n const removeChip = (chipToRemove: string) => {\n const newValue = value.filter((chip) => chip !== chipToRemove);\n updateValue(newValue);\n setAnnouncement(replacePlaceholder(removedAnnouncementTemplate, chipToRemove)!);\n };\n\n /**\n * Moves a chip from one position to another.\n * @param start The starting index of the item to move\n * @param end The ending index where the item should be placed\n */\n const onDrop = (start: number, end: number) => {\n // Clone existing elements\n const newItems = [...value];\n // Remove the element to be moved\n const item = newItems.splice(start, 1);\n // Add it back at the required position\n newItems.splice(end, 0, item[0]);\n // Update\n updateValue(newItems);\n };\n\n // Render the component\n return (\n <>\n <Label\n text={text}\n touched={touched}\n errorText={props.errorText}\n required={props.required}\n width={props.width}\n >\n <input\n {...props}\n ref={InputRef}\n value={text}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyUp={handleKeyUp}\n required={props.required && value.length === 0}\n aria-required={props.required}\n aria-invalid={!!props.errorText}\n aria-describedby={props.errorText ? errorId : undefined}\n />\n <div>\n {value?.length > 0 && (\n <DragAndDrop orientation={ORIENTATION.HORIZONTAL} onDrop={onDrop}>\n {value.map((chip) => (\n <Chip\n key={chip}\n label={chip}\n onCloseClick={() => removeChip(chip)}\n closeButtonAriaLabel={replacePlaceholder(\n closeButtonAriaLabel,\n chip,\n )}\n />\n ))}\n </DragAndDrop>\n )}\n </div>\n <span>{props.label}</span>\n {props.errorText && <ErrorContainer id={errorId}>{props.errorText}</ErrorContainer>}\n </Label>\n <VisuallyHidden aria-live=\"polite\" aria-atomic=\"true\">\n {announcement}\n </VisuallyHidden>\n </>\n );\n}\n\nconst ChipInput = React.forwardRef<\n HTMLInputElement,\n ChipInputProps & Omit<React.AllHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'>\n>(ChipInputComponent);\n\nexport default ChipInput;\n"],"names":["Label","styled","getThemeValue","THEME_NAME","BORDER_COLOR","BACKGROUND","props","width","PRIMARY","PRIMARY_LIGHT","DISABLED_BORDER","DISABLED_BACKGROUND","DISABLED","ERROR","ERROR_LIGHT","touched","errorText","required","text","ErrorContainer","VisuallyHidden","ChipInputComponent","ref","value","propValue","closeButtonAriaLabel","addedAnnouncementTemplate","removedAnnouncementTemplate","setText","useState","setTouched","setValue","InputRef","React","useRef","announcement","setAnnouncement","errorId","useId","useImperativeHandle","current","replacePlaceholder","template","label","undefined","replace","prevPropValueRef","useEffect","Array","isArray","prevValue","isEqual","length","every","val","index","updateValue","newValue","deduped","from","Set","onChange","handleFocus","e","onFocus","handleChange","target","handleKeyUp","key","trim","validity","valid","removeChip","chipToRemove","filter","chip","onDrop","start","end","newItems","item","splice","_jsxs","_Fragment","_jsx","input","onKeyUp","aria-required","aria-invalid","aria-describedby","div","DragAndDrop","orientation","ORIENTATION","HORIZONTAL","map","Chip","onCloseClick","span","id","aria-live","aria-atomic","ChipInput","forwardRef"],"mappings":";;;;;;;;AAoCA;AACA,MAAMA,OAAAA,iBAAQC,MAAAA,CAAAA,OAAAA,EAAAA;;;AAeUC,CAAAA,CAAAA,CAAAA,oJAAAA,EAAAA,aAAAA,CAAcC,UAAAA,CAAWC,YAAY,CAAA,EAAA,oBAAA,EACrCF,aAAAA,CAAcC,UAAAA,CAAWE,UAAU,CAAA,EAAA,SAAA,EAC9C,CAACC,KAAAA,GACN,OAAOA,KAAAA,CAAMC,KAAK,KAAK,QAAA,GAAW,CAAA,EAAGD,KAAAA,CAAMC,KAAK,CAAC,EAAE,CAAC,GAAGD,KAAAA,CAAMC,KAAK,IAAI,OAAA,EAAA,4DAAA,EAMtDL,aAAAA,CAAcC,UAAAA,CAAWK,OAAO,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CAACc,MAAAA,EAAAA;AAAM5F,wBAAAA,QAAAA,EAAAA,KAAAA,CAAMqC;;oBACZrC,KAAAA,CAAMU,SAAS,kBAAIoE,GAAA,CAACjE,gBAAAA,EAAAA;wBAAegF,EAAAA,EAAI9D,OAAAA;AAAU/B,wBAAAA,QAAAA,EAAAA,KAAAA,CAAMU;;;;0BAE5DoE,GAAA,CAAChE,gBAAAA,EAAAA;gBAAegF,WAAAA,EAAU,QAAA;gBAASC,aAAAA,EAAY,MAAA;AAC1ClE,gBAAAA,QAAAA,EAAAA;;;;AAIjB;AAEA,MAAMmE,SAAAA,iBAAYrE,KAAAA,CAAMsE,UAAU,CAGhClF,kBAAAA;;;;"}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
type AlertOption =
|
|
2
|
+
import Dialog from './Dialog';
|
|
3
|
+
type AlertOption = {
|
|
4
|
+
/** Shown as header of the dialog */
|
|
5
|
+
header: string;
|
|
6
|
+
/** Rendered in the body. */
|
|
7
|
+
body: React.ReactNode;
|
|
8
|
+
/** Accept button text */
|
|
9
|
+
buttonText?: string;
|
|
10
|
+
/** props for the dialog */
|
|
11
|
+
dialogProps?: React.ComponentProps<typeof Dialog>;
|
|
12
|
+
};
|
|
4
13
|
export default class AlertDialog extends React.Component<AlertOption> {
|
|
5
14
|
private dialog;
|
|
6
|
-
static propTypes: {
|
|
7
|
-
/** Shown as header of the dialog */
|
|
8
|
-
header: PropTypes.Requireable<string>;
|
|
9
|
-
/** Rendered in the body. */
|
|
10
|
-
body: PropTypes.Validator<any>;
|
|
11
|
-
/** Accept button text, default value is `OK` */
|
|
12
|
-
buttonText: PropTypes.Requireable<string>;
|
|
13
|
-
/** props for the dialog */
|
|
14
|
-
dialogProps: PropTypes.Requireable<object>;
|
|
15
|
-
};
|
|
16
15
|
static defaultProps: {
|
|
17
16
|
buttonText: string;
|
|
18
17
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import React, { createRef } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
3
|
import Dialog from './Dialog.js';
|
|
5
4
|
import { Header, Body, Footer } from '../../shared/styles.js';
|
|
6
|
-
import
|
|
5
|
+
import Button from '../Button/Button.js';
|
|
7
6
|
|
|
8
7
|
let dialogCounter = 0;
|
|
9
8
|
class AlertDialog extends React.Component {
|
|
@@ -28,7 +27,7 @@ class AlertDialog extends React.Component {
|
|
|
28
27
|
children: this.props.body
|
|
29
28
|
}),
|
|
30
29
|
/*#__PURE__*/ jsx(Footer, {
|
|
31
|
-
children: /*#__PURE__*/ jsx(
|
|
30
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
32
31
|
onClick: this.close,
|
|
33
32
|
children: this.props.buttonText
|
|
34
33
|
})
|
|
@@ -40,17 +39,11 @@ class AlertDialog extends React.Component {
|
|
|
40
39
|
super(...args), this.dialog = /*#__PURE__*/ createRef(), this.show = ()=>{
|
|
41
40
|
return new Promise((resolve)=>{
|
|
42
41
|
const onClose = ()=>resolve(null);
|
|
43
|
-
this.dialog.current
|
|
42
|
+
this.dialog.current?.open(onClose);
|
|
44
43
|
});
|
|
45
|
-
}, this.close = ()=>this.dialog.current
|
|
44
|
+
}, this.close = ()=>this.dialog.current?.close();
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
AlertDialog.propTypes = {
|
|
49
|
-
/** Shown as header of the dialog */ header: PropTypes.string,
|
|
50
|
-
/** Rendered in the body. */ body: PropTypes.any.isRequired,
|
|
51
|
-
/** Accept button text, default value is `OK` */ buttonText: PropTypes.string,
|
|
52
|
-
/** props for the dialog */ dialogProps: PropTypes.object
|
|
53
|
-
};
|
|
54
47
|
AlertDialog.defaultProps = {
|
|
55
48
|
buttonText: 'OK'
|
|
56
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlertDialog.js","sources":["../../../src/components/Dialog/AlertDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"AlertDialog.js","sources":["../../../src/components/Dialog/AlertDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport { Button } from '../Button';\nimport Dialog, { DialogBody, DialogFooter, DialogHeader } from './Dialog';\n\ntype AlertOption = {\n /** Shown as header of the dialog */\n header: string;\n /** Rendered in the body. */\n body: React.ReactNode;\n /** Accept button text */\n buttonText?: string;\n /** props for the dialog */\n dialogProps?: React.ComponentProps<typeof Dialog>;\n};\n\nlet dialogCounter = 0;\n\nexport default class AlertDialog extends React.Component<AlertOption> {\n private dialog = createRef<Dialog>();\n\n static defaultProps = {\n buttonText: 'OK',\n };\n\n public show = () => {\n return new Promise((resolve) => {\n const onClose = () => resolve(null);\n this.dialog.current?.open(onClose);\n });\n };\n\n private close = () => this.dialog.current?.close();\n\n render() {\n const titleId = `nfui-alert-dialog-${dialogCounter++}-title`;\n const descriptionId = `nfui-alert-dialog-${dialogCounter++}-description`;\n\n return (\n <Dialog\n {...this.props.dialogProps}\n role=\"alertdialog\"\n aria-labelledby={titleId}\n aria-describedby={descriptionId}\n ref={this.dialog}\n closeOnEsc={false}\n closeOnOverlayClick={false}\n >\n {this.props.header && <DialogHeader id={titleId}>{this.props.header}</DialogHeader>}\n <DialogBody id={descriptionId}>{this.props.body}</DialogBody>\n <DialogFooter>\n <Button onClick={this.close}>{this.props.buttonText}</Button>\n </DialogFooter>\n </Dialog>\n );\n }\n}\n"],"names":["dialogCounter","AlertDialog","React","Component","render","titleId","descriptionId","_jsxs","Dialog","props","dialogProps","role","aria-labelledby","aria-describedby","ref","dialog","closeOnEsc","closeOnOverlayClick","header","_jsx","DialogHeader","id","DialogBody","body","DialogFooter","Button","onClick","close","buttonText","createRef","show","Promise","resolve","onClose","current","open","defaultProps"],"mappings":";;;;;;AAeA,IAAIA,aAAAA,GAAgB,CAAA;AAEL,MAAMC,WAAAA,SAAoBC,MAAMC,SAA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A,IAAA,CAEQN,QAAQ,IAAM,IAAI,CAACZ,MAAM,CAACmB,OAAO,EAAEP,KAAAA,EAAAA;;AAwB/C;AAtCqB1B,WAAAA,CAGVmC,YAAAA,GAAe;IAClBR,UAAAA,EAAY;AAChB,CAAA;;;;"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
type ConfirmOption =
|
|
2
|
+
import Dialog from './Dialog';
|
|
3
|
+
type ConfirmOption = {
|
|
4
|
+
/** Shown as header of the dialog */
|
|
5
|
+
header: string;
|
|
6
|
+
/** Rendered as body of the dialog */
|
|
7
|
+
body: string;
|
|
8
|
+
/** Accept button text */
|
|
9
|
+
yesText?: string;
|
|
10
|
+
/** Reject button text */
|
|
11
|
+
noText?: string;
|
|
12
|
+
/** Props for the dialog */
|
|
13
|
+
dialogProps?: React.ComponentProps<typeof Dialog>;
|
|
14
|
+
};
|
|
4
15
|
export default class ConfirmDialog extends React.Component<ConfirmOption> {
|
|
5
16
|
private dialog;
|
|
6
|
-
static propTypes: {
|
|
7
|
-
/** Shown as header of the dialog */
|
|
8
|
-
header: PropTypes.Requireable<string>;
|
|
9
|
-
/** Rendered as body of the dialog */
|
|
10
|
-
body: PropTypes.Validator<string>;
|
|
11
|
-
/** Accept button text */
|
|
12
|
-
yesText: PropTypes.Requireable<string>;
|
|
13
|
-
/** Reject button text */
|
|
14
|
-
noText: PropTypes.Requireable<string>;
|
|
15
|
-
/** Props for the dialog */
|
|
16
|
-
dialogProps: PropTypes.Requireable<object>;
|
|
17
|
-
};
|
|
18
17
|
static defaultProps: {
|
|
19
18
|
yesText: string;
|
|
20
19
|
noText: string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import React, { createRef } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
3
|
import Dialog from './Dialog.js';
|
|
5
4
|
import { Header, Body, Footer } from '../../shared/styles.js';
|
|
6
|
-
import
|
|
5
|
+
import Button from '../Button/Button.js';
|
|
7
6
|
import ActionButton from '../Button/ActionButton.js';
|
|
8
7
|
|
|
9
8
|
class ConfirmDialog extends React.Component {
|
|
@@ -23,7 +22,7 @@ class ConfirmDialog extends React.Component {
|
|
|
23
22
|
}),
|
|
24
23
|
/*#__PURE__*/ jsxs(Footer, {
|
|
25
24
|
children: [
|
|
26
|
-
/*#__PURE__*/ jsx(
|
|
25
|
+
/*#__PURE__*/ jsx(Button, {
|
|
27
26
|
onClick: this.cancel,
|
|
28
27
|
children: noText
|
|
29
28
|
}),
|
|
@@ -46,18 +45,11 @@ class ConfirmDialog extends React.Component {
|
|
|
46
45
|
reject();
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
|
-
this.dialog.current
|
|
48
|
+
this.dialog.current?.open(onClose);
|
|
50
49
|
});
|
|
51
|
-
}, this.cancel = ()=>this.dialog.current
|
|
50
|
+
}, this.cancel = ()=>this.dialog.current?.close(false), this.confirm = ()=>this.dialog.current?.close(true);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
ConfirmDialog.propTypes = {
|
|
55
|
-
/** Shown as header of the dialog */ header: PropTypes.string,
|
|
56
|
-
/** Rendered as body of the dialog */ body: PropTypes.string.isRequired,
|
|
57
|
-
/** Accept button text */ yesText: PropTypes.string,
|
|
58
|
-
/** Reject button text */ noText: PropTypes.string,
|
|
59
|
-
/** Props for the dialog */ dialogProps: PropTypes.object
|
|
60
|
-
};
|
|
61
53
|
ConfirmDialog.defaultProps = {
|
|
62
54
|
yesText: 'Yes',
|
|
63
55
|
noText: 'No'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmDialog.js","sources":["../../../src/components/Dialog/ConfirmDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"ConfirmDialog.js","sources":["../../../src/components/Dialog/ConfirmDialog.tsx"],"sourcesContent":["import React, { createRef } from 'react';\nimport { Button, ActionButton } from '../Button';\nimport Dialog, { DialogBody, DialogFooter, DialogHeader } from './Dialog';\n\ntype ConfirmOption = {\n /** Shown as header of the dialog */\n header: string;\n /** Rendered as body of the dialog */\n body: string;\n /** Accept button text */\n yesText?: string;\n /** Reject button text */\n noText?: string;\n /** Props for the dialog */\n dialogProps?: React.ComponentProps<typeof Dialog>;\n};\n\nexport default class ConfirmDialog extends React.Component<ConfirmOption> {\n private dialog = createRef<Dialog>();\n\n static defaultProps = {\n yesText: 'Yes',\n noText: 'No',\n };\n\n public show = () => {\n return new Promise((resolve, reject) => {\n const onClose = (resp: unknown) => {\n if (resp) {\n resolve(null);\n } else {\n reject();\n }\n };\n this.dialog.current?.open(onClose);\n });\n };\n\n private cancel = () => this.dialog.current?.close(false);\n private confirm = () => this.dialog.current?.close(true);\n\n render() {\n const { header, body, yesText, noText, dialogProps } = this.props;\n return (\n <Dialog\n {...dialogProps}\n ref={this.dialog}\n closeOnEsc={false}\n closeOnOverlayClick={false}\n >\n {header && <DialogHeader>{header}</DialogHeader>}\n <DialogBody>{body}</DialogBody>\n <DialogFooter>\n <Button onClick={this.cancel}>{noText}</Button>\n <ActionButton onClick={this.confirm}>{yesText}</ActionButton>\n </DialogFooter>\n </Dialog>\n );\n }\n}\n"],"names":["ConfirmDialog","React","Component","render","header","body","yesText","noText","dialogProps","props","_jsxs","Dialog","ref","dialog","closeOnEsc","closeOnOverlayClick","_jsx","DialogHeader","DialogBody","DialogFooter","Button","onClick","cancel","ActionButton","confirm","createRef","show","Promise","resolve","reject","onClose","resp","current","open","close","defaultProps"],"mappings":";;;;;;;AAiBe,MAAMA,aAAAA,SAAsBC,MAAMC,SAAS,CAAA;IAwBtDC,MAAAA,GAAS;AACL,QAAA,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAG,IAAI,CAACC,KAAK;AACjE,QAAA,qBACIC,IAAA,CAACC,MAAAA,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BvD;AA1CqBlC,aAAAA,CAGVmC,YAAAA,GAAe;IAClB7B,OAAAA,EAAS,KAAA;IACTC,MAAAA,EAAQ;AACZ,CAAA;;;;"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
export declare const DialogContainer: import("@emotion/styled").StyledComponent<{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} & import("../Card/Card").CardExtraProps & React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & {
|
|
3
|
+
elevated?: boolean;
|
|
4
|
+
} & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement> & {
|
|
7
5
|
theme?: import("@emotion/react").Theme;
|
|
8
6
|
}, {}, {}>;
|
|
9
7
|
export { Header as DialogHeader, Body as DialogBody, Footer as DialogFooter, } from '../../shared/styles';
|
|
@@ -12,18 +10,14 @@ interface DialogOptions {
|
|
|
12
10
|
closeOnEsc?: boolean;
|
|
13
11
|
/** Close layer overlay is clicked. Default value is true. */
|
|
14
12
|
closeOnOverlayClick?: boolean;
|
|
13
|
+
/** Ref forwarded to the underlying HTMLDivElement of the dialog container */
|
|
14
|
+
forwardRef?: React.Ref<HTMLDivElement>;
|
|
15
15
|
}
|
|
16
16
|
interface DialogState {
|
|
17
17
|
show: boolean;
|
|
18
|
-
LayerComponent?:
|
|
18
|
+
LayerComponent?: React.ComponentType | null;
|
|
19
19
|
}
|
|
20
|
-
declare class Dialog extends React.Component<React.PropsWithChildren<DialogOptions> &
|
|
21
|
-
static propTypes: {
|
|
22
|
-
/** Flag to close dialog on `esc` click. Default value is true. */
|
|
23
|
-
closeOnEsc: PropTypes.Requireable<boolean>;
|
|
24
|
-
/** Close layer overlay is clicked. Default value is true. */
|
|
25
|
-
closeOnOverlayClick: PropTypes.Requireable<boolean>;
|
|
26
|
-
};
|
|
20
|
+
declare class Dialog extends React.Component<React.PropsWithChildren<DialogOptions> & React.HTMLAttributes<HTMLDivElement>, DialogState> {
|
|
27
21
|
static defaultProps: {
|
|
28
22
|
closeOnEsc: boolean;
|
|
29
23
|
closeOnOverlayClick: boolean;
|
|
@@ -58,9 +52,9 @@ declare class Dialog extends React.Component<React.PropsWithChildren<DialogOptio
|
|
|
58
52
|
private setInitialFocus;
|
|
59
53
|
shouldComponentUpdate(nextProps: DialogOptions, nextState: DialogState): boolean;
|
|
60
54
|
componentWillUnmount(): void;
|
|
61
|
-
open: (closeCallback?: (resp
|
|
55
|
+
open: (closeCallback?: (resp?: unknown) => void) => void;
|
|
62
56
|
close: (resp?: unknown) => void;
|
|
63
57
|
private closeCallback;
|
|
64
|
-
render(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
58
|
+
render(): import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
65
59
|
}
|
|
66
60
|
export default Dialog;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { jsx } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
3
|
import styled from '@emotion/styled';
|
|
5
4
|
import LayerManager, { LAYER_POSITION } from '../../shared/LayerManager.js';
|
|
6
5
|
import Card from '../Card/Card.js';
|
|
7
6
|
|
|
8
7
|
const DialogContainer = /*#__PURE__*/ styled(Card, {
|
|
9
|
-
target: "
|
|
8
|
+
target: "e1sxvvof0",
|
|
10
9
|
label: "DialogContainer"
|
|
11
10
|
})("max-width:768px;max-height:80vh;transform:scale(0);opacity:0;transition:all 0.3s ease;.nf-layer-enter &{opacity:1;transform:scale(1);}.nf-layer-exit &{opacity:0;transform:scale(0);}");
|
|
12
11
|
class Dialog extends React.Component {
|
|
@@ -31,7 +30,7 @@ class Dialog extends React.Component {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
constructor(...args){
|
|
34
|
-
super(...args), this.lastFocusedElement = null, this.dialogRef = /*#__PURE__*/ React.createRef(), this.state = {
|
|
33
|
+
super(...args), this.closeDialog = null, this.onCloseFn = null, this.lastFocusedElement = null, this.dialogRef = /*#__PURE__*/ React.createRef(), this.state = {
|
|
35
34
|
show: false,
|
|
36
35
|
LayerComponent: undefined
|
|
37
36
|
}, /**
|
|
@@ -80,6 +79,13 @@ class Dialog extends React.Component {
|
|
|
80
79
|
if (node) {
|
|
81
80
|
this.setInitialFocus(node);
|
|
82
81
|
}
|
|
82
|
+
if (this.props.forwardRef) {
|
|
83
|
+
if (typeof this.props.forwardRef === 'function') {
|
|
84
|
+
this.props.forwardRef(node);
|
|
85
|
+
} else {
|
|
86
|
+
this.props.forwardRef.current = node;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
}, /**
|
|
84
90
|
* Sets initial focus within the dialog.
|
|
85
91
|
* Tries to focus the header first, then the first interactive element, or falls back to the container.
|
|
@@ -110,9 +116,9 @@ class Dialog extends React.Component {
|
|
|
110
116
|
closeOnOverlayClick,
|
|
111
117
|
position: LAYER_POSITION.DIALOG,
|
|
112
118
|
component: /*#__PURE__*/ jsx(DialogContainer, {
|
|
119
|
+
role: "dialog",
|
|
113
120
|
...rest,
|
|
114
121
|
ref: this.setDialogRef,
|
|
115
|
-
role: "dialog",
|
|
116
122
|
"aria-modal": "true",
|
|
117
123
|
tabIndex: -1,
|
|
118
124
|
onKeyDown: this.handleKeyDown,
|
|
@@ -126,7 +132,7 @@ class Dialog extends React.Component {
|
|
|
126
132
|
show: true,
|
|
127
133
|
LayerComponent: Component
|
|
128
134
|
});
|
|
129
|
-
this.onCloseFn = closeCallback;
|
|
135
|
+
this.onCloseFn = closeCallback ?? null;
|
|
130
136
|
}, this.close = (resp)=>{
|
|
131
137
|
this.closeDialog?.(resp);
|
|
132
138
|
}, this.closeCallback = (resp)=>{
|
|
@@ -139,10 +145,6 @@ class Dialog extends React.Component {
|
|
|
139
145
|
};
|
|
140
146
|
}
|
|
141
147
|
}
|
|
142
|
-
Dialog.propTypes = {
|
|
143
|
-
/** Flag to close dialog on `esc` click. Default value is true. */ closeOnEsc: PropTypes.bool,
|
|
144
|
-
/** Close layer overlay is clicked. Default value is true. */ closeOnOverlayClick: PropTypes.bool
|
|
145
|
-
};
|
|
146
148
|
Dialog.defaultProps = {
|
|
147
149
|
closeOnEsc: true,
|
|
148
150
|
closeOnOverlayClick: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sources":["../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport styled from '@emotion/styled';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\nimport { Card } from '../Card';\n\nexport const DialogContainer = styled(Card)`\n max-width: 768px;\n max-height: 80vh;\n transform: scale(0);\n opacity: 0;\n transition: all 0.3s ease;\n\n .nf-layer-enter & {\n opacity: 1;\n transform: scale(1);\n }\n\n .nf-layer-exit & {\n opacity: 0;\n transform: scale(0);\n }\n`;\n\nexport {\n Header as DialogHeader,\n Body as DialogBody,\n Footer as DialogFooter,\n} from '../../shared/styles';\n\ninterface DialogOptions {\n /** Flag to close dialog on `esc` click. Default value is true. */\n closeOnEsc?: boolean;\n /** Close layer overlay is clicked. Default value is true. */\n closeOnOverlayClick?: boolean;\n}\n\ninterface DialogState {\n show: boolean;\n LayerComponent?: () => React.ReactPortal | null;\n}\n\nclass Dialog extends React.Component<\n React.PropsWithChildren<DialogOptions> & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'ref'>,\n DialogState\n> {\n static propTypes = {\n /** Flag to close dialog on `esc` click. Default value is true. */\n closeOnEsc: PropTypes.bool,\n /** Close layer overlay is clicked. Default value is true. */\n closeOnOverlayClick: PropTypes.bool,\n };\n\n static defaultProps = {\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n private closeDialog: (resp?: unknown) => void;\n private onCloseFn: (resp?: unknown) => void;\n private lastFocusedElement: HTMLElement | null = null;\n private dialogRef = React.createRef<HTMLDivElement>();\n\n state: DialogState = {\n show: false,\n LayerComponent: undefined,\n };\n\n /**\n * Retrieves all focusable elements within the dialog.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.dialogRef.current) return [];\n return Array.from(\n this.dialogRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n ),\n ) as HTMLElement[];\n };\n\n /**\n * Handles keydown events to implement the focus trap.\n * Traps Tab and Shift+Tab within the dialog.\n */\n private handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Tab') {\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length === 0) return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey) {\n if (document.activeElement === firstElement) {\n lastElement.focus();\n e.preventDefault();\n }\n } else {\n if (document.activeElement === lastElement) {\n firstElement.focus();\n e.preventDefault();\n }\n }\n }\n };\n\n /**\n * Restores focus to the element that was focused before the dialog opened.\n */\n private restoreFocus = () => {\n if (this.lastFocusedElement) {\n const elementToBeFocused = this.lastFocusedElement;\n this.lastFocusedElement = null;\n setTimeout(() => {\n if (document.body.contains(elementToBeFocused)) {\n elementToBeFocused.focus();\n }\n }, 100);\n }\n };\n\n /**\n * Callback ref to capture the Dialog DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setDialogRef = (node: HTMLDivElement | null) => {\n (this.dialogRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\n if (node) {\n this.setInitialFocus(node);\n }\n };\n\n /**\n * Sets initial focus within the dialog.\n * Tries to focus the header first, then the first interactive element, or falls back to the container.\n */\n private setInitialFocus = (root: HTMLElement) => {\n const firstChild = root.firstElementChild as HTMLElement;\n if (firstChild) {\n if (firstChild.getAttribute('tabindex') === null) {\n firstChild.setAttribute('tabindex', '-1');\n }\n firstChild.focus();\n return;\n }\n\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n } else {\n root.focus();\n }\n };\n\n shouldComponentUpdate(nextProps: DialogOptions, nextState: DialogState) {\n return this.state.show !== nextState.show;\n }\n\n componentWillUnmount() {\n // Clean up if component unmounts while dialog is open\n if (this.state.show && this.closeDialog) {\n this.closeDialog();\n }\n this.restoreFocus();\n this.closeDialog = null;\n this.onCloseFn = null;\n }\n\n public open = (closeCallback?: (resp: unknown) => void) => {\n const { closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;\n\n // Save current focus\n this.lastFocusedElement = document.activeElement as HTMLElement;\n\n const [Component, closeFn] = LayerManager.renderLayer({\n exitDelay: 300,\n overlay: true,\n closeOnEsc,\n closeCallback: this.closeCallback,\n closeOnOverlayClick,\n position: LAYER_POSITION.DIALOG,\n component: (\n <DialogContainer\n {...rest}\n ref={this.setDialogRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n onKeyDown={this.handleKeyDown}\n onClick={(e) => e.stopPropagation()}\n elevated\n >\n {children}\n </DialogContainer>\n ),\n });\n\n this.closeDialog = closeFn;\n\n this.setState({\n show: true,\n LayerComponent: Component,\n });\n this.onCloseFn = closeCallback;\n };\n\n public close = (resp?: unknown) => {\n this.closeDialog?.(resp);\n };\n\n private closeCallback = (resp?: unknown) => {\n this.restoreFocus();\n this.setState({\n show: false,\n LayerComponent: undefined,\n });\n this.onCloseFn?.(resp);\n };\n\n render() {\n const { LayerComponent } = this.state;\n\n if (this.state.show && LayerComponent) {\n return <LayerComponent />;\n } else {\n return null;\n }\n }\n}\n\nexport default Dialog;\n"],"names":["DialogContainer","styled","Card","Dialog","React","Component","shouldComponentUpdate","nextProps","nextState","state","show","componentWillUnmount","closeDialog","restoreFocus","onCloseFn","render","LayerComponent","_jsx","lastFocusedElement","dialogRef","createRef","undefined","getFocusableElements","current","Array","from","querySelectorAll","handleKeyDown","e","key","focusableElements","length","firstElement","lastElement","shiftKey","document","activeElement","focus","preventDefault","elementToBeFocused","setTimeout","body","contains","setDialogRef","node","setInitialFocus","root","firstChild","firstElementChild","getAttribute","setAttribute","open","closeCallback","closeOnEsc","closeOnOverlayClick","children","rest","props","closeFn","LayerManager","renderLayer","exitDelay","overlay","position","LAYER_POSITION","DIALOG","component","ref","role","aria-modal","tabIndex","onKeyDown","onClick","stopPropagation","elevated","setState","close","resp","propTypes","PropTypes","bool","defaultProps"],"mappings":";;;;;;;AAMO,MAAMA,gCAAkBC,MAAAA,CAAOC,IAAAA,EAAAA;;;AAgBpC,CAAA,CAAA,CAAA,uLAAA;AAoBF,MAAMC,MAAAA,SAAeC,MAAMC,SAAS,CAAA;IAiHhCC,qBAAAA,CAAsBC,SAAwB,EAAEC,SAAsB,EAAE;AACpE,QAAA,OAAO,IAAI,CAACC,KAAK,CAACC,IAAI,KAAKF,UAAUE,IAAI;AAC7C,IAAA;IAEAC,oBAAAA,GAAuB;;QAEnB,IAAI,IAAI,CAACF,KAAK,CAACC,IAAI,IAAI,IAAI,CAACE,WAAW,EAAE;AACrC,YAAA,IAAI,CAACA,WAAW,EAAA;AACpB,QAAA;AACA,QAAA,IAAI,CAACC,YAAY,EAAA;QACjB,IAAI,CAACD,WAAW,GAAG,IAAA;QACnB,IAAI,CAACE,SAAS,GAAG,IAAA;AACrB,IAAA;IAqDAC,MAAAA,GAAS;AACL,QAAA,MAAM,EAAEC,cAAc,EAAE,GAAG,IAAI,CAACP,KAAK;AAErC,QAAA,IAAI,IAAI,CAACA,KAAK,CAACC,IAAI,IAAIM,cAAAA,EAAgB;AACnC,YAAA,qBAAOC,GAAA,CAACD,cAAAA,EAAAA,EAAAA,CAAAA;QACZ,CAAA,MAAO;YACH,OAAO,IAAA;AACX,QAAA;AACJ,IAAA;;AA1LJ,QAAA,KAAA,CAAA,GAAA,IAAA,CAAA,EAAA,IAAA,CAkBYE,qBAAyC,IAAA,EAAA,IAAA,CACzCC,SAAAA,iBAAYf,KAAAA,CAAMgB,SAAS,SAEnCX,KAAAA,GAAqB;YACjBC,IAAAA,EAAM,KAAA;YACNM,cAAAA,EAAgBK;SACpB;;AAIC,QAAA,IAAA,CACOC,oBAAAA,GAAuB,I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AEfzB,UAAAA,EAAY0B,SAAAA,CAAUC,IAAI;kEAE1B1B,mBAAAA,EAAqByB,SAAAA,CAAUC;AACnC,CAAA;AATE7E,MAAAA,CAWK8E,YAAAA,GAAe;IAClB5B,UAAAA,EAAY,IAAA;IACZC,mBAAAA,EAAqB;AACzB,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"Dialog.js","sources":["../../../src/components/Dialog/Dialog.tsx"],"sourcesContent":["import React from 'react';\nimport styled from '@emotion/styled';\nimport LayerManager, { LAYER_POSITION } from '../../shared/LayerManager';\nimport { Card } from '../Card';\n\nexport const DialogContainer = styled(Card)`\n max-width: 768px;\n max-height: 80vh;\n transform: scale(0);\n opacity: 0;\n transition: all 0.3s ease;\n\n .nf-layer-enter & {\n opacity: 1;\n transform: scale(1);\n }\n\n .nf-layer-exit & {\n opacity: 0;\n transform: scale(0);\n }\n`;\n\nexport {\n Header as DialogHeader,\n Body as DialogBody,\n Footer as DialogFooter,\n} from '../../shared/styles';\n\ninterface DialogOptions {\n /** Flag to close dialog on `esc` click. Default value is true. */\n closeOnEsc?: boolean;\n /** Close layer overlay is clicked. Default value is true. */\n closeOnOverlayClick?: boolean;\n /** Ref forwarded to the underlying HTMLDivElement of the dialog container */\n forwardRef?: React.Ref<HTMLDivElement>;\n}\n\ninterface DialogState {\n show: boolean;\n LayerComponent?: React.ComponentType | null;\n}\n\nclass Dialog extends React.Component<\n React.PropsWithChildren<DialogOptions> & React.HTMLAttributes<HTMLDivElement>,\n DialogState\n> {\n static defaultProps = {\n closeOnEsc: true,\n closeOnOverlayClick: true,\n };\n\n private closeDialog: ((resp?: unknown) => void) | null = null;\n private onCloseFn: ((resp?: unknown) => void) | null = null;\n private lastFocusedElement: HTMLElement | null = null;\n private dialogRef = React.createRef<HTMLDivElement>();\n\n state: DialogState = {\n show: false,\n LayerComponent: undefined,\n };\n\n /**\n * Retrieves all focusable elements within the dialog.\n */\n private getFocusableElements = (): HTMLElement[] => {\n if (!this.dialogRef.current) return [];\n return Array.from(\n this.dialogRef.current.querySelectorAll(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])',\n ),\n ) as HTMLElement[];\n };\n\n /**\n * Handles keydown events to implement the focus trap.\n * Traps Tab and Shift+Tab within the dialog.\n */\n private handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Tab') {\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length === 0) return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements[focusableElements.length - 1];\n\n if (e.shiftKey) {\n if (document.activeElement === firstElement) {\n lastElement.focus();\n e.preventDefault();\n }\n } else {\n if (document.activeElement === lastElement) {\n firstElement.focus();\n e.preventDefault();\n }\n }\n }\n };\n\n /**\n * Restores focus to the element that was focused before the dialog opened.\n */\n private restoreFocus = () => {\n if (this.lastFocusedElement) {\n const elementToBeFocused = this.lastFocusedElement;\n this.lastFocusedElement = null;\n setTimeout(() => {\n if (document.body.contains(elementToBeFocused)) {\n elementToBeFocused.focus();\n }\n }, 100);\n }\n };\n\n /**\n * Callback ref to capture the Dialog DOM element.\n * Triggers initial focus setting when the element mounts.\n */\n private setDialogRef = (node: HTMLDivElement | null) => {\n (this.dialogRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\n if (node) {\n this.setInitialFocus(node);\n }\n\n if (this.props.forwardRef) {\n if (typeof this.props.forwardRef === 'function') {\n this.props.forwardRef(node);\n } else {\n (this.props.forwardRef as React.MutableRefObject<HTMLDivElement | null>).current =\n node;\n }\n }\n };\n\n /**\n * Sets initial focus within the dialog.\n * Tries to focus the header first, then the first interactive element, or falls back to the container.\n */\n private setInitialFocus = (root: HTMLElement) => {\n const firstChild = root.firstElementChild as HTMLElement;\n if (firstChild) {\n if (firstChild.getAttribute('tabindex') === null) {\n firstChild.setAttribute('tabindex', '-1');\n }\n firstChild.focus();\n return;\n }\n\n const focusableElements = this.getFocusableElements();\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n } else {\n root.focus();\n }\n };\n\n shouldComponentUpdate(nextProps: DialogOptions, nextState: DialogState) {\n return this.state.show !== nextState.show;\n }\n\n componentWillUnmount() {\n // Clean up if component unmounts while dialog is open\n if (this.state.show && this.closeDialog) {\n this.closeDialog();\n }\n this.restoreFocus();\n this.closeDialog = null;\n this.onCloseFn = null;\n }\n\n public open = (closeCallback?: (resp?: unknown) => void) => {\n const { closeOnEsc, closeOnOverlayClick, children, ...rest } = this.props;\n\n // Save current focus\n this.lastFocusedElement = document.activeElement as HTMLElement;\n\n const [Component, closeFn] = LayerManager.renderLayer({\n exitDelay: 300,\n overlay: true,\n closeOnEsc,\n closeCallback: this.closeCallback,\n closeOnOverlayClick,\n position: LAYER_POSITION.DIALOG,\n component: (\n <DialogContainer\n role=\"dialog\"\n {...rest}\n ref={this.setDialogRef}\n aria-modal=\"true\"\n tabIndex={-1}\n onKeyDown={this.handleKeyDown}\n onClick={(e) => e.stopPropagation()}\n elevated\n >\n {children}\n </DialogContainer>\n ),\n });\n\n this.closeDialog = closeFn;\n\n this.setState({\n show: true,\n LayerComponent: Component,\n });\n this.onCloseFn = closeCallback ?? null;\n };\n\n public close = (resp?: unknown) => {\n this.closeDialog?.(resp);\n };\n\n private closeCallback = (resp?: unknown) => {\n this.restoreFocus();\n this.setState({\n show: false,\n LayerComponent: undefined,\n });\n this.onCloseFn?.(resp);\n };\n\n render() {\n const { LayerComponent } = this.state;\n\n if (this.state.show && LayerComponent) {\n return <LayerComponent />;\n } else {\n return null;\n }\n }\n}\n\nexport default Dialog;\n"],"names":["DialogContainer","styled","Card","Dialog","React","Component","shouldComponentUpdate","nextProps","nextState","state","show","componentWillUnmount","closeDialog","restoreFocus","onCloseFn","render","LayerComponent","_jsx","lastFocusedElement","dialogRef","createRef","undefined","getFocusableElements","current","Array","from","querySelectorAll","handleKeyDown","e","key","focusableElements","length","firstElement","lastElement","shiftKey","document","activeElement","focus","preventDefault","elementToBeFocused","setTimeout","body","contains","setDialogRef","node","setInitialFocus","props","forwardRef","root","firstChild","firstElementChild","getAttribute","setAttribute","open","closeCallback","closeOnEsc","closeOnOverlayClick","children","rest","closeFn","LayerManager","renderLayer","exitDelay","overlay","position","LAYER_POSITION","DIALOG","component","role","ref","aria-modal","tabIndex","onKeyDown","onClick","stopPropagation","elevated","setState","close","resp","defaultProps"],"mappings":";;;;;;AAKO,MAAMA,gCAAkBC,MAAAA,CAAOC,IAAAA,EAAAA;;;AAgBpC,CAAA,CAAA,CAAA,uLAAA;AAsBF,MAAMC,MAAAA,SAAeC,MAAMC,SAAS,CAAA;IAmHhCC,qBAAAA,CAAsBC,SAAwB,EAAEC,SAAsB,EAAE;AACpE,QAAA,OAAO,IAAI,CAACC,KAAK,CAACC,IAAI,KAAKF,UAAUE,IAAI;AAC7C,IAAA;IAEAC,oBAAAA,GAAuB;;QAEnB,IAAI,IAAI,CAACF,KAAK,CAACC,IAAI,IAAI,IAAI,CAACE,WAAW,EAAE;AACrC,YAAA,IAAI,CAACA,WAAW,EAAA;AACpB,QAAA;AACA,QAAA,IAAI,CAACC,YAAY,EAAA;QACjB,IAAI,CAACD,WAAW,GAAG,IAAA;QACnB,IAAI,CAACE,SAAS,GAAG,IAAA;AACrB,IAAA;IAqDAC,MAAAA,GAAS;AACL,QAAA,MAAM,EAAEC,cAAc,EAAE,GAAG,IAAI,CAACP,KAAK;AAErC,QAAA,IAAI,IAAI,CAACA,KAAK,CAACC,IAAI,IAAIM,cAAAA,EAAgB;AACnC,YAAA,qBAAOC,GAAA,CAACD,cAAAA,EAAAA,EAAAA,CAAAA;QACZ,CAAA,MAAO;YACH,OAAO,IAAA;AACX,QAAA;AACJ,IAAA;;QA5LJ,KAAA,CAAA,GAAA,IAAA,CAAA,EAAA,IAAA,CASYJ,WAAAA,GAAiD,IAAA,EAAA,IAAA,CACjDE,SAAAA,GAA+C,IAAA,EAAA,IAAA,CAC/CI,kBAAAA,GAAyC,WACzCC,SAAAA,iBAAYf,KAAAA,CAAMgB,SAAS,EAAA,EAAA,IAAA,CAEnCX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AiB,IAAA;AACtC,QAAA,CAAA,EAAA,IAAA,CAEOuB,QAAQ,CAACC,IAAAA,GAAAA;YACZ,IAAI,CAAClE,WAAW,GAAGkE,IAAAA,CAAAA;AACvB,QAAA,CAAA,EAAA,IAAA,CAEQxB,gBAAgB,CAACwB,IAAAA,GAAAA;AACrB,YAAA,IAAI,CAACjE,YAAY,EAAA;YACjB,IAAI,CAAC+D,QAAQ,CAAC;gBACVlE,IAAAA,EAAM,KAAA;gBACNM,cAAAA,EAAgBK;AACpB,aAAA,CAAA;YACA,IAAI,CAACP,SAAS,GAAGgE,IAAAA,CAAAA;AACrB,QAAA,CAAA;;AAWJ;AA7LM3E,MAAAA,CAIK4E,YAAAA,GAAe;IAClBxB,UAAAA,EAAY,IAAA;IACZC,mBAAAA,EAAqB;AACzB,CAAA;;;;"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
type PromptOption =
|
|
2
|
+
import Dialog from './Dialog';
|
|
3
|
+
type PromptOption = {
|
|
4
|
+
/** Shown as header of the dialog */
|
|
5
|
+
header: string;
|
|
6
|
+
/** Rendered as the body of the dialog */
|
|
7
|
+
body: string;
|
|
8
|
+
/** Default value for the input. */
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
/** Submit button text. Default value is 'Submit' */
|
|
11
|
+
submitText?: string;
|
|
12
|
+
/** Cancel button text. Default value is 'Cancel' */
|
|
13
|
+
cancelText?: string;
|
|
14
|
+
/** Props for the input. */
|
|
15
|
+
inputProps?: React.HTMLProps<HTMLInputElement>;
|
|
16
|
+
/** Additional props for the dialog. */
|
|
17
|
+
dialogProps?: React.ComponentProps<typeof Dialog>;
|
|
18
|
+
};
|
|
4
19
|
export default class PromptDialog extends React.Component<PromptOption, {
|
|
5
|
-
value
|
|
20
|
+
value?: string;
|
|
6
21
|
}> {
|
|
7
|
-
static propTypes: {
|
|
8
|
-
/** Shown as header of the dialog */
|
|
9
|
-
header: PropTypes.Requireable<string>;
|
|
10
|
-
/** Rendered as the body of the dialog */
|
|
11
|
-
body: PropTypes.Requireable<string>;
|
|
12
|
-
/** Default value for the input. */
|
|
13
|
-
defaultValue: PropTypes.Requireable<string>;
|
|
14
|
-
/** Submit button text. Default value is 'Submit' */
|
|
15
|
-
submitText: PropTypes.Requireable<string>;
|
|
16
|
-
/** Cancel button text. Default value is 'Cancel' */
|
|
17
|
-
cancelText: PropTypes.Requireable<string>;
|
|
18
|
-
/** Props for the input. */
|
|
19
|
-
inputProps: PropTypes.Requireable<object>;
|
|
20
|
-
/** Additional props for the dialog. */
|
|
21
|
-
dialogProps: PropTypes.Requireable<object>;
|
|
22
|
-
};
|
|
23
22
|
static defaultProps: {
|
|
24
23
|
cancelText: string;
|
|
25
24
|
submitText: string;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import React, { createRef } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
3
|
import styled from '@emotion/styled';
|
|
5
4
|
import Dialog from './Dialog.js';
|
|
6
5
|
import { Header, Body, Footer } from '../../shared/styles.js';
|
|
7
|
-
import
|
|
6
|
+
import Button from '../Button/Button.js';
|
|
8
7
|
import ActionButton from '../Button/ActionButton.js';
|
|
9
8
|
import Input from '../Input/Input.js';
|
|
10
9
|
|
|
11
10
|
const BodyText = /*#__PURE__*/ styled("p", {
|
|
12
|
-
target: "
|
|
11
|
+
target: "e18k0mlw0",
|
|
13
12
|
label: "BodyText"
|
|
14
13
|
})("margin-top:0;");
|
|
15
14
|
const InputContainer = /*#__PURE__*/ styled("div", {
|
|
16
|
-
target: "
|
|
15
|
+
target: "e18k0mlw1",
|
|
17
16
|
label: "InputContainer"
|
|
18
17
|
})("display:flex;flex:1;margin-top:10px;& > label{flex:1;width:100%;padding:0;& > input{width:100%;padding:0 8px;box-sizing:border-box;}}");
|
|
19
18
|
const StyledInput = /*#__PURE__*/ styled(Input, {
|
|
20
|
-
target: "
|
|
19
|
+
target: "e18k0mlw2",
|
|
21
20
|
label: "StyledInput"
|
|
22
21
|
})("flex:1;padding:0;");
|
|
23
22
|
class PromptDialog extends React.Component {
|
|
@@ -50,12 +49,13 @@ class PromptDialog extends React.Component {
|
|
|
50
49
|
}),
|
|
51
50
|
/*#__PURE__*/ jsxs(Footer, {
|
|
52
51
|
children: [
|
|
53
|
-
/*#__PURE__*/ jsx(
|
|
52
|
+
/*#__PURE__*/ jsx(Button, {
|
|
54
53
|
type: "button",
|
|
55
54
|
onClick: this.cancel,
|
|
56
55
|
children: cancelText
|
|
57
56
|
}),
|
|
58
57
|
/*#__PURE__*/ jsx(ActionButton, {
|
|
58
|
+
onClick: this.submit,
|
|
59
59
|
children: submitText
|
|
60
60
|
})
|
|
61
61
|
]
|
|
@@ -69,9 +69,10 @@ class PromptDialog extends React.Component {
|
|
|
69
69
|
this.setState({
|
|
70
70
|
value: e.target.value
|
|
71
71
|
});
|
|
72
|
-
}, this.cancel = ()=>this.dialog.current
|
|
72
|
+
}, this.cancel = ()=>this.dialog.current?.close(), this.submit = (e)=>{
|
|
73
73
|
e.preventDefault();
|
|
74
|
-
|
|
74
|
+
if (!this.state.value) return;
|
|
75
|
+
this.dialog.current?.close(this.state.value);
|
|
75
76
|
}, this.show = ()=>{
|
|
76
77
|
return new Promise((resolve, reject)=>{
|
|
77
78
|
const onClose = (value)=>{
|
|
@@ -84,7 +85,7 @@ class PromptDialog extends React.Component {
|
|
|
84
85
|
value: this.props.defaultValue
|
|
85
86
|
});
|
|
86
87
|
};
|
|
87
|
-
this.dialog.current
|
|
88
|
+
this.dialog.current?.open(onClose);
|
|
88
89
|
});
|
|
89
90
|
};
|
|
90
91
|
this.state = {
|
|
@@ -92,15 +93,6 @@ class PromptDialog extends React.Component {
|
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
PromptDialog.propTypes = {
|
|
96
|
-
/** Shown as header of the dialog */ header: PropTypes.string,
|
|
97
|
-
/** Rendered as the body of the dialog */ body: PropTypes.string,
|
|
98
|
-
/** Default value for the input. */ defaultValue: PropTypes.string,
|
|
99
|
-
/** Submit button text. Default value is 'Submit' */ submitText: PropTypes.string,
|
|
100
|
-
/** Cancel button text. Default value is 'Cancel' */ cancelText: PropTypes.string,
|
|
101
|
-
/** Props for the input. */ inputProps: PropTypes.object,
|
|
102
|
-
/** Additional props for the dialog. */ dialogProps: PropTypes.object
|
|
103
|
-
};
|
|
104
96
|
PromptDialog.defaultProps = {
|
|
105
97
|
cancelText: 'Cancel',
|
|
106
98
|
submitText: 'Submit',
|