@danske/sapphire-react-lab 0.76.0
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/LICENSE +7 -0
- package/README.md +15 -0
- package/build/cjs/index.js +2876 -0
- package/build/cjs/index.js.map +1 -0
- package/build/esm/Accordion/index.js +11 -0
- package/build/esm/Accordion/index.js.map +1 -0
- package/build/esm/Accordion/src/Accordion.js +72 -0
- package/build/esm/Accordion/src/Accordion.js.map +1 -0
- package/build/esm/Accordion/src/AccordionHeading.js +49 -0
- package/build/esm/Accordion/src/AccordionHeading.js.map +1 -0
- package/build/esm/Accordion/src/AccordionItem.js +68 -0
- package/build/esm/Accordion/src/AccordionItem.js.map +1 -0
- package/build/esm/Accordion/src/useTreeState.js +42 -0
- package/build/esm/Accordion/src/useTreeState.js.map +1 -0
- package/build/esm/Avatar/src/Avatar.js +63 -0
- package/build/esm/Avatar/src/Avatar.js.map +1 -0
- package/build/esm/Calendar/i18n/da-DK.js +9 -0
- package/build/esm/Calendar/i18n/da-DK.js.map +1 -0
- package/build/esm/Calendar/i18n/de-DE.js +9 -0
- package/build/esm/Calendar/i18n/de-DE.js.map +1 -0
- package/build/esm/Calendar/i18n/en-US.js +9 -0
- package/build/esm/Calendar/i18n/en-US.js.map +1 -0
- package/build/esm/Calendar/i18n/fi-FI.js +9 -0
- package/build/esm/Calendar/i18n/fi-FI.js.map +1 -0
- package/build/esm/Calendar/i18n/index.js +20 -0
- package/build/esm/Calendar/i18n/index.js.map +1 -0
- package/build/esm/Calendar/i18n/nb-NO.js +9 -0
- package/build/esm/Calendar/i18n/nb-NO.js.map +1 -0
- package/build/esm/Calendar/i18n/pl-PL.js +9 -0
- package/build/esm/Calendar/i18n/pl-PL.js.map +1 -0
- package/build/esm/Calendar/i18n/sv-SE.js +9 -0
- package/build/esm/Calendar/i18n/sv-SE.js.map +1 -0
- package/build/esm/Calendar/src/Calendar.js +122 -0
- package/build/esm/Calendar/src/Calendar.js.map +1 -0
- package/build/esm/Calendar/src/CalendarButtons.js +96 -0
- package/build/esm/Calendar/src/CalendarButtons.js.map +1 -0
- package/build/esm/Calendar/src/CalendarDaysGrid.js +169 -0
- package/build/esm/Calendar/src/CalendarDaysGrid.js.map +1 -0
- package/build/esm/Calendar/src/CalendarHeader.js +58 -0
- package/build/esm/Calendar/src/CalendarHeader.js.map +1 -0
- package/build/esm/Calendar/src/CalendarMonthOrYearCell.js +79 -0
- package/build/esm/Calendar/src/CalendarMonthOrYearCell.js.map +1 -0
- package/build/esm/Calendar/src/CalendarMonthsGrid.js +58 -0
- package/build/esm/Calendar/src/CalendarMonthsGrid.js.map +1 -0
- package/build/esm/Calendar/src/CalendarPageAnimation.js +67 -0
- package/build/esm/Calendar/src/CalendarPageAnimation.js.map +1 -0
- package/build/esm/Calendar/src/CalendarYearsGrid.js +52 -0
- package/build/esm/Calendar/src/CalendarYearsGrid.js.map +1 -0
- package/build/esm/Calendar/src/RangeCalendar.js +119 -0
- package/build/esm/Calendar/src/RangeCalendar.js.map +1 -0
- package/build/esm/Calendar/src/useCustomDurationCalendarGrid.js +57 -0
- package/build/esm/Calendar/src/useCustomDurationCalendarGrid.js.map +1 -0
- package/build/esm/Calendar/src/useRangeCalendarState.js +57 -0
- package/build/esm/Calendar/src/useRangeCalendarState.js.map +1 -0
- package/build/esm/Calendar/src/useSapphireCalendarState.js +86 -0
- package/build/esm/Calendar/src/useSapphireCalendarState.js.map +1 -0
- package/build/esm/Calendar/src/utils.js +12 -0
- package/build/esm/Calendar/src/utils.js.map +1 -0
- package/build/esm/DateField/i18n/da-DK.js +7 -0
- package/build/esm/DateField/i18n/da-DK.js.map +1 -0
- package/build/esm/DateField/i18n/de-DE.js +7 -0
- package/build/esm/DateField/i18n/de-DE.js.map +1 -0
- package/build/esm/DateField/i18n/en-US.js +7 -0
- package/build/esm/DateField/i18n/en-US.js.map +1 -0
- package/build/esm/DateField/i18n/fi-FI.js +7 -0
- package/build/esm/DateField/i18n/fi-FI.js.map +1 -0
- package/build/esm/DateField/i18n/index.js +20 -0
- package/build/esm/DateField/i18n/index.js.map +1 -0
- package/build/esm/DateField/i18n/nb-NO.js +7 -0
- package/build/esm/DateField/i18n/nb-NO.js.map +1 -0
- package/build/esm/DateField/i18n/pl-PL.js +7 -0
- package/build/esm/DateField/i18n/pl-PL.js.map +1 -0
- package/build/esm/DateField/i18n/sv-SE.js +7 -0
- package/build/esm/DateField/i18n/sv-SE.js.map +1 -0
- package/build/esm/DateField/src/DateField.js +126 -0
- package/build/esm/DateField/src/DateField.js.map +1 -0
- package/build/esm/DateField/src/DateFieldButton.js +44 -0
- package/build/esm/DateField/src/DateFieldButton.js.map +1 -0
- package/build/esm/DateField/src/DateInput.js +81 -0
- package/build/esm/DateField/src/DateInput.js.map +1 -0
- package/build/esm/DateField/src/DateRangeField.js +151 -0
- package/build/esm/DateField/src/DateRangeField.js.map +1 -0
- package/build/esm/DateField/src/DateRangeInput.js +90 -0
- package/build/esm/DateField/src/DateRangeInput.js.map +1 -0
- package/build/esm/DateField/src/DateSegment.js +52 -0
- package/build/esm/DateField/src/DateSegment.js.map +1 -0
- package/build/esm/DateField/src/helpers.js +14 -0
- package/build/esm/DateField/src/helpers.js.map +1 -0
- package/build/esm/DateField/src/useDateRangePickerState.js +57 -0
- package/build/esm/DateField/src/useDateRangePickerState.js.map +1 -0
- package/build/esm/DateField/src/utils/placeholders.js +91 -0
- package/build/esm/DateField/src/utils/placeholders.js.map +1 -0
- package/build/esm/DateField/src/utils/segments.js +46 -0
- package/build/esm/DateField/src/utils/segments.js.map +1 -0
- package/build/esm/FeedbackMessage/src/FeedbackMessage.js +55 -0
- package/build/esm/FeedbackMessage/src/FeedbackMessage.js.map +1 -0
- package/build/esm/Fieldset/src/Fieldset.js +77 -0
- package/build/esm/Fieldset/src/Fieldset.js.map +1 -0
- package/build/esm/Filtering/src/FilterDropdown.js +61 -0
- package/build/esm/Filtering/src/FilterDropdown.js.map +1 -0
- package/build/esm/NotificationBadge/src/NotificationBadge.js +72 -0
- package/build/esm/NotificationBadge/src/NotificationBadge.js.map +1 -0
- package/build/esm/SearchField/src/SearchField.js +115 -0
- package/build/esm/SearchField/src/SearchField.js.map +1 -0
- package/build/esm/SearchField/src/useComboBoxState.js +42 -0
- package/build/esm/SearchField/src/useComboBoxState.js.map +1 -0
- package/build/esm/Spinner/src/Spinner.js +46 -0
- package/build/esm/Spinner/src/Spinner.js.map +1 -0
- package/build/esm/Toast/src/Toast.js +66 -0
- package/build/esm/Toast/src/Toast.js.map +1 -0
- package/build/esm/Toast/src/ToastProvider.js +53 -0
- package/build/esm/Toast/src/ToastProvider.js.map +1 -0
- package/build/esm/Toast/src/ToastRegion.js +56 -0
- package/build/esm/Toast/src/ToastRegion.js.map +1 -0
- package/build/esm/Toast/src/context.js +10 -0
- package/build/esm/Toast/src/context.js.map +1 -0
- package/build/esm/Toast/src/useShowToast.js +15 -0
- package/build/esm/Toast/src/useShowToast.js.map +1 -0
- package/build/esm/ToggleButton/src/ToggleButton.js +85 -0
- package/build/esm/ToggleButton/src/ToggleButton.js.map +1 -0
- package/build/esm/Typography/index.js +14 -0
- package/build/esm/Typography/index.js.map +1 -0
- package/build/esm/Typography/src/Body.js +66 -0
- package/build/esm/Typography/src/Body.js.map +1 -0
- package/build/esm/Typography/src/Caption.js +59 -0
- package/build/esm/Typography/src/Caption.js.map +1 -0
- package/build/esm/Typography/src/Heading.js +55 -0
- package/build/esm/Typography/src/Heading.js.map +1 -0
- package/build/esm/Typography/src/Subheading.js +63 -0
- package/build/esm/Typography/src/Subheading.js.map +1 -0
- package/build/esm/index.js +21 -0
- package/build/esm/index.js.map +1 -0
- package/build/index.d.ts +746 -0
- package/package.json +65 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useSearchField } from '@react-aria/searchfield';
|
|
4
|
+
import { useThemeCheck, useSapphireStyleProps, useButton, Icon, ListBoxPopover } from '@danske/sapphire-react';
|
|
5
|
+
import styles from '@danske/sapphire-css/components/searchField/searchField.module.css';
|
|
6
|
+
import { useSearchFieldState } from '@react-stately/searchfield';
|
|
7
|
+
import { useObjectRef, mergeProps } from '@react-aria/utils';
|
|
8
|
+
import { Search, CloseCircle } from '@danske/sapphire-icons/react';
|
|
9
|
+
import { useFocusableRef } from '@react-spectrum/utils';
|
|
10
|
+
import { useComboBoxState } from './useComboBoxState.js';
|
|
11
|
+
import { useComboBox } from '@react-aria/combobox';
|
|
12
|
+
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __defProps = Object.defineProperties;
|
|
15
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
16
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
17
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
19
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
20
|
+
var __spreadValues = (a, b) => {
|
|
21
|
+
for (var prop in b || (b = {}))
|
|
22
|
+
if (__hasOwnProp.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
if (__getOwnPropSymbols)
|
|
25
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
26
|
+
if (__propIsEnum.call(b, prop))
|
|
27
|
+
__defNormalProp(a, prop, b[prop]);
|
|
28
|
+
}
|
|
29
|
+
return a;
|
|
30
|
+
};
|
|
31
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
32
|
+
const SearchField = React.forwardRef(function SearchField2(props, forwardedRef) {
|
|
33
|
+
var _a;
|
|
34
|
+
useThemeCheck();
|
|
35
|
+
const inputRef = useObjectRef(forwardedRef);
|
|
36
|
+
const buttonRef = useRef(null);
|
|
37
|
+
const listBoxRef = useFocusableRef(null);
|
|
38
|
+
const popoverRef = useRef(null);
|
|
39
|
+
const triggerRef = useFocusableRef(null);
|
|
40
|
+
const {
|
|
41
|
+
styleProps: { style, className }
|
|
42
|
+
} = useSapphireStyleProps(props);
|
|
43
|
+
const state = useComboBoxState(__spreadProps(__spreadValues({}, props), {
|
|
44
|
+
inputValue: props.value,
|
|
45
|
+
defaultInputValue: props.defaultValue,
|
|
46
|
+
onInputChange: props.onChange,
|
|
47
|
+
allowsEmptyCollection: false,
|
|
48
|
+
allowsCustomValue: true,
|
|
49
|
+
shouldCloseOnBlur: true
|
|
50
|
+
}));
|
|
51
|
+
const { inputProps: comboBoxInputProps, listBoxProps } = useComboBox(__spreadProps(__spreadValues({}, props), {
|
|
52
|
+
inputRef,
|
|
53
|
+
listBoxRef,
|
|
54
|
+
popoverRef
|
|
55
|
+
}), state);
|
|
56
|
+
const searchProps = {
|
|
57
|
+
"aria-label": props["aria-label"],
|
|
58
|
+
"aria-labelledby": props["aria-labelledby"],
|
|
59
|
+
isDisabled: props.isDisabled,
|
|
60
|
+
isReadOnly: props.isReadOnly,
|
|
61
|
+
value: state.inputValue,
|
|
62
|
+
onSubmit: (value) => {
|
|
63
|
+
var _a2;
|
|
64
|
+
if (!state.selectionManager.isFocused) {
|
|
65
|
+
(_a2 = props == null ? void 0 : props.onSubmit) == null ? void 0 : _a2.call(props, value);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
onClear: () => {
|
|
69
|
+
var _a2;
|
|
70
|
+
state.setInputValue("");
|
|
71
|
+
(_a2 = props.onClear) == null ? void 0 : _a2.call(props);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const searchFieldState = useSearchFieldState(searchProps);
|
|
75
|
+
const { clearButtonProps, inputProps: searchFieldInputProps } = useSearchField(searchProps, searchFieldState, inputRef);
|
|
76
|
+
const { buttonProps } = useButton(__spreadProps(__spreadValues({}, clearButtonProps), {
|
|
77
|
+
elementType: "div"
|
|
78
|
+
}), buttonRef);
|
|
79
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
80
|
+
className: clsx(styles["sapphire-search-field"], className, {
|
|
81
|
+
[styles["sapphire-search-field--medium"]]: props.size === "medium",
|
|
82
|
+
[styles["sapphire-search-field--surface-secondary"]]: props.surface === "secondary",
|
|
83
|
+
[styles["is-disabled"]]: props.isDisabled
|
|
84
|
+
}),
|
|
85
|
+
style,
|
|
86
|
+
ref: triggerRef
|
|
87
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
88
|
+
className: styles["sapphire-search-field__icon"]
|
|
89
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
90
|
+
size: props.size === "medium" ? "m" : "l"
|
|
91
|
+
}, /* @__PURE__ */ React.createElement(Search, null))), /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({}, mergeProps(comboBoxInputProps, searchFieldInputProps)), {
|
|
92
|
+
ref: inputRef,
|
|
93
|
+
className: clsx(styles["sapphire-search-field__input"], {
|
|
94
|
+
[styles["sapphire-search-field__input--empty"]]: state.inputValue.length === 0
|
|
95
|
+
})
|
|
96
|
+
})), /* @__PURE__ */ React.createElement("div", __spreadValues({
|
|
97
|
+
ref: buttonRef,
|
|
98
|
+
className: styles["sapphire-search-field__button"]
|
|
99
|
+
}, buttonProps), /* @__PURE__ */ React.createElement(Icon, {
|
|
100
|
+
size: props.size === "medium" ? "m" : "l"
|
|
101
|
+
}, /* @__PURE__ */ React.createElement(CloseCircle, null))), state.isOpen && /* @__PURE__ */ React.createElement(ListBoxPopover, {
|
|
102
|
+
state,
|
|
103
|
+
triggerRef,
|
|
104
|
+
popoverRef,
|
|
105
|
+
listBoxRef,
|
|
106
|
+
listBoxProps,
|
|
107
|
+
selectWidth: ((_a = triggerRef.current) == null ? void 0 : _a.offsetWidth) || 0,
|
|
108
|
+
size: props.size,
|
|
109
|
+
disableSelectedStyles: true,
|
|
110
|
+
isNonModal: true
|
|
111
|
+
}, props.children || []));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export { SearchField };
|
|
115
|
+
//# sourceMappingURL=SearchField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchField.js","sources":["../../../../src/SearchField/src/SearchField.tsx"],"sourcesContent":["import React, { ForwardedRef, useRef } from 'react';\nimport clsx from 'clsx';\nimport { HelpTextProps, LabelableProps, Validation } from '@react-types/shared';\nimport type { ComboBoxProps } from '@react-types/combobox';\nimport { AriaSearchFieldProps, useSearchField } from '@react-aria/searchfield';\n\nimport {\n SapphireStyleProps,\n useButton,\n useSapphireStyleProps,\n useThemeCheck,\n ListBoxPopover,\n Icon,\n} from '@danske/sapphire-react';\nimport styles from '@danske/sapphire-css/components/searchField/searchField.module.css';\nimport { useSearchFieldState } from '@react-stately/searchfield';\nimport { mergeProps, useObjectRef } from '@react-aria/utils';\nimport { CloseCircle, Search } from '@danske/sapphire-icons/react';\nimport { useFocusableRef } from '@react-spectrum/utils';\nimport { useComboBoxState } from './useComboBoxState';\nimport { useComboBox } from '@react-aria/combobox';\n\nexport type SapphireSearchFieldProps<T extends object> = SapphireStyleProps &\n Omit<\n AriaSearchFieldProps,\n keyof HelpTextProps | keyof Validation<unknown> | keyof LabelableProps\n > &\n AutocompleteProps<T> & {\n /**\n * @default 'large'\n */\n size?: 'large' | 'medium';\n /**\n * Adjusts the style for the type of surface it is rendered on.\n * @default 'primary'\n */\n surface?: 'primary' | 'secondary';\n } & (\n | { 'aria-labelledby': string }\n | {\n 'aria-label': string;\n }\n );\n\n// we don't want props related to \"selection\" because from the POV of the\n// autocomplete feature, there is no concept of \"selection\"\ntype AutocompleteProps<T extends object> = {\n items?: ComboBoxProps<T>['items'];\n defaultItems?: ComboBoxProps<T>['defaultItems'];\n children?: ComboBoxProps<T>['children'];\n onOpenChange?: ComboBoxProps<T>['onOpenChange'];\n defaultFilter?: (textValue: string, inputValue: string) => boolean;\n};\n\n/**\n * Sapphire search input field.\n */\nexport const SearchField = React.forwardRef(function SearchField<\n T extends object\n>(\n props: SapphireSearchFieldProps<T>,\n forwardedRef: ForwardedRef<HTMLInputElement>\n): JSX.Element {\n useThemeCheck();\n\n const inputRef = useObjectRef(forwardedRef);\n const buttonRef = useRef<HTMLDivElement>(null);\n const listBoxRef = useFocusableRef<HTMLUListElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const triggerRef = useFocusableRef<HTMLDivElement>(null);\n const {\n styleProps: { style, className },\n } = useSapphireStyleProps(props);\n\n const state = useComboBoxState({\n ...props,\n inputValue: props.value,\n defaultInputValue: props.defaultValue,\n onInputChange: props.onChange,\n allowsEmptyCollection: false,\n allowsCustomValue: true,\n shouldCloseOnBlur: true,\n });\n\n const { inputProps: comboBoxInputProps, listBoxProps } = useComboBox(\n {\n ...props,\n inputRef,\n listBoxRef,\n popoverRef,\n },\n state\n );\n\n /**\n * In order to compose the `useSearchField` and `useComboBox` we want to:\n * - let the combobox control the input but\n * - allow the search field's \"clear\" and \"submit\" behavior\n *\n * For this, we take control of `useSearchField` and not pass the props\n * indiscriminately.\n *\n * For example think about using `onBlur` on `SearchField`. The combobox\n * hook gets that prop and the input props we get back will add that\n * listener to the input. We don't want the input props from\n * `useSearchField` to add the same listener.\n */\n const searchProps: AriaSearchFieldProps = {\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'],\n isDisabled: props.isDisabled,\n isReadOnly: props.isReadOnly,\n // needed for the submit functionality\n value: state.inputValue,\n onSubmit: (value) => {\n if (!state.selectionManager.isFocused) {\n props?.onSubmit?.(value);\n }\n },\n onClear: () => {\n state.setInputValue('');\n props.onClear?.();\n },\n };\n\n const searchFieldState = useSearchFieldState(searchProps);\n\n const { clearButtonProps, inputProps: searchFieldInputProps } =\n useSearchField(searchProps, searchFieldState, inputRef);\n\n const { buttonProps } = useButton(\n {\n ...clearButtonProps,\n elementType: 'div',\n },\n buttonRef\n );\n\n return (\n <div\n className={clsx(styles['sapphire-search-field'], className, {\n [styles['sapphire-search-field--medium']]: props.size === 'medium',\n [styles['sapphire-search-field--surface-secondary']]:\n props.surface === 'secondary',\n [styles['is-disabled']]: props.isDisabled,\n })}\n style={style}\n ref={triggerRef}\n >\n <span className={styles['sapphire-search-field__icon']}>\n <Icon size={props.size === 'medium' ? 'm' : 'l'}>\n <Search />\n </Icon>\n </span>\n <input\n {...mergeProps(comboBoxInputProps, searchFieldInputProps)}\n ref={inputRef}\n className={clsx(styles['sapphire-search-field__input'], {\n [styles['sapphire-search-field__input--empty']]:\n state.inputValue.length === 0,\n })}\n />\n <div\n ref={buttonRef}\n className={styles['sapphire-search-field__button']}\n {...buttonProps}\n >\n <Icon size={props.size === 'medium' ? 'm' : 'l'}>\n <CloseCircle />\n </Icon>\n </div>\n {state.isOpen && (\n <ListBoxPopover<T>\n state={state}\n triggerRef={triggerRef}\n popoverRef={popoverRef}\n listBoxRef={listBoxRef}\n listBoxProps={listBoxProps}\n selectWidth={triggerRef.current?.offsetWidth || 0}\n size={props.size}\n disableSelectedStyles\n isNonModal\n >\n {props.children || []}\n </ListBoxPopover>\n )}\n </div>\n );\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAM,WAAc,GAAA,KAAA,CAAM,UAAW,CAAA,SAAA,YAAA,CAG1C,OACA,YACa,EAAA;AA9Df,EAAA,IAAA,EAAA,CAAA;AA+DE,EAAA,aAAA,EAAA,CAAA;AAEA,EAAA,MAAM,WAAW,YAAa,CAAA,YAAA,CAAA,CAAA;AAC9B,EAAA,MAAM,YAAY,MAAuB,CAAA,IAAA,CAAA,CAAA;AACzC,EAAA,MAAM,aAAa,eAAkC,CAAA,IAAA,CAAA,CAAA;AACrD,EAAA,MAAM,aAAa,MAAuB,CAAA,IAAA,CAAA,CAAA;AAC1C,EAAA,MAAM,aAAa,eAAgC,CAAA,IAAA,CAAA,CAAA;AACnD,EAAM,MAAA;AAAA,IACJ,UAAA,EAAY,EAAE,KAAO,EAAA,SAAA,EAAA;AAAA,GAAA,GACnB,qBAAsB,C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cAAA,CAAA,EAAA,EAAA,UAAA,CAAW,oBAAoB,qBADrC,CAAA,CAAA,EAAA;AAAA,IAEE,GAAK,EAAA,QAAA;AAAA,IACL,SAAA,EAAW,IAAK,CAAA,MAAA,CAAO,8BAAiC,CAAA,EAAA;AAAA,MAAA,CACrD,MAAO,CAAA,qCAAA,CAAA,GACN,KAAM,CAAA,UAAA,CAAW,MAAW,KAAA,CAAA;AAAA,KAAA,CAAA;AAAA,GAAA,CAAA,CAAA,sCAGjC,KAAD,EAAA,cAAA,CAAA;AAAA,IACE,GAAK,EAAA,SAAA;AAAA,IACL,WAAW,MAAO,CAAA,+BAAA,CAAA;AAAA,GACd,EAAA,WAAA,CAAA,sCAEH,IAAD,EAAA;AAAA,IAAM,IAAM,EAAA,KAAA,CAAM,IAAS,KAAA,QAAA,GAAW,GAAM,GAAA,GAAA;AAAA,GAAA,sCACzC,WAAD,EAAA,IAAA,CAAA,CAAA,CAAA,EAGH,KAAM,CAAA,MAAA,wCACJ,cAAD,EAAA;AAAA,IACE,KAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAa,EAAA,CAAA,CAAA,EAAA,GAAA,UAAA,CAAW,OAAX,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAoB,WAAe,KAAA,CAAA;AAAA,IAChD,MAAM,KAAM,CAAA,IAAA;AAAA,IACZ,qBAAqB,EAAA,IAAA;AAAA,IACrB,UAAU,EAAA,IAAA;AAAA,GAAA,EAET,MAAM,QAAY,IAAA,EAAA,CAAA,CAAA,CAAA;AAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useComboBoxState as useComboBoxState$1 } from '@react-stately/combobox';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
const useComboBoxState = (options) => {
|
|
23
|
+
const state = useComboBoxState$1(__spreadProps(__spreadValues({}, options), {
|
|
24
|
+
defaultFilter: (textValue, query) => {
|
|
25
|
+
if (query.length > 0) {
|
|
26
|
+
return options.defaultFilter ? options.defaultFilter(textValue, query) : textValue.toLowerCase().includes(query.toLowerCase());
|
|
27
|
+
} else {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
33
|
+
open: (focusStrategy, triggerMode) => {
|
|
34
|
+
if (triggerMode !== "manual") {
|
|
35
|
+
state.open(focusStrategy, triggerMode);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { useComboBoxState };
|
|
42
|
+
//# sourceMappingURL=useComboBoxState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComboBoxState.js","sources":["../../../../src/SearchField/src/useComboBoxState.ts"],"sourcesContent":["import { useComboBoxState as originalUseComboBoxState } from '@react-stately/combobox';\n\n/**\n * A wrapper for `useComboBoxState` to make the combobox more like \"autocomplete\":\n *\n * 1) We don't want to allow opening the combobox \"manually\".\n * In react-aria terms \"manual\" opening means where the user explicitly\n * wants to open the popover.\n * In the autocomplete feature we don't want such behaviour because the\n * popover has the role of assisting typing, not \"selecting\" a value.\n *\n * 2) We don't want to show any options if the query is empty.\n *\n * More details here\n * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/combobox/src/useComboBox.ts\n */\nexport const useComboBoxState: typeof originalUseComboBoxState = (options) => {\n const state = originalUseComboBoxState({\n ...options,\n defaultFilter: (textValue, query) => {\n if (query.length > 0) {\n return options.defaultFilter\n ? options.defaultFilter(textValue, query)\n : textValue.toLowerCase().includes(query.toLowerCase());\n } else {\n return false;\n }\n },\n });\n return {\n ...state,\n open: (focusStrategy, triggerMode) => {\n if (triggerMode !== 'manual') {\n state.open(focusStrategy, triggerMode);\n }\n },\n };\n};\n"],"names":["originalUseComboBoxState"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgBa,MAAA,gBAAA,GAAoD,CAAC,OAAY,KAAA;AAC5E,EAAM,MAAA,KAAA,GAAQA,kBAAyB,CAAA,aAAA,CAAA,cAAA,CAAA,EAAA,EAClC,OADkC,CAAA,EAAA;AAAA,IAErC,aAAA,EAAe,CAAC,SAAA,EAAW,KAAU,KAAA;AACnC,MAAI,IAAA,KAAA,CAAM,SAAS,CAAG,EAAA;AACpB,QAAO,OAAA,OAAA,CAAQ,gBACX,OAAQ,CAAA,aAAA,CAAc,WAAW,KACjC,CAAA,GAAA,SAAA,CAAU,WAAc,EAAA,CAAA,QAAA,CAAS,KAAM,CAAA,WAAA,EAAA,CAAA,CAAA;AAAA,OACtC,MAAA;AACL,QAAO,OAAA,KAAA,CAAA;AAAA,OAAA;AAAA,KAAA;AAAA,GAAA,CAAA,CAAA,CAAA;AAIb,EAAA,OAAO,iCACF,KADE,CAAA,EAAA;AAAA,IAEL,IAAA,EAAM,CAAC,aAAA,EAAe,WAAgB,KAAA;AACpC,MAAA,IAAI,gBAAgB,QAAU,EAAA;AAC5B,QAAA,KAAA,CAAM,KAAK,aAAe,EAAA,WAAA,CAAA,CAAA;AAAA,OAAA;AAAA,KAAA;AAAA,GAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import styles from '@danske/sapphire-css/components/spinner/spinner.module.css';
|
|
4
|
+
import { useThemeCheck, useSapphireStyleProps } from '@danske/sapphire-react';
|
|
5
|
+
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __objRest = (source, exclude) => {
|
|
10
|
+
var target = {};
|
|
11
|
+
for (var prop in source)
|
|
12
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
13
|
+
target[prop] = source[prop];
|
|
14
|
+
if (source != null && __getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
16
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
17
|
+
target[prop] = source[prop];
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
const Spinner = (_a) => {
|
|
22
|
+
var _b = _a, {
|
|
23
|
+
size = "m"
|
|
24
|
+
} = _b, props = __objRest(_b, [
|
|
25
|
+
"size"
|
|
26
|
+
]);
|
|
27
|
+
useThemeCheck();
|
|
28
|
+
const { styleProps } = useSapphireStyleProps(props);
|
|
29
|
+
return /* @__PURE__ */ React.createElement("svg", {
|
|
30
|
+
role: "progressbar",
|
|
31
|
+
"aria-label": "aria-label" in props ? props["aria-label"] : void 0,
|
|
32
|
+
"aria-labelledby": "aria-labelledby" in props ? props["aria-labelledby"] : void 0,
|
|
33
|
+
className: clsx(styleProps.className, styles["sapphire-spinner"], size !== "m" ? styles[`sapphire-spinner--${size}`] : ""),
|
|
34
|
+
style: styleProps.style,
|
|
35
|
+
viewBox: "0 0 16 16"
|
|
36
|
+
}, /* @__PURE__ */ React.createElement("path", {
|
|
37
|
+
className: styles["sapphire-spinner__track"],
|
|
38
|
+
d: "M10.3993 2.13882C10.3295 2.39914 10.4641 2.66858 10.7034 2.79263C11.2238 3.06246 11.7123 3.41501 12.1489 3.85159C14.4401 6.14281 14.4399 9.85728 12.1489 12.1483C9.85783 14.4393 6.14335 14.4395 3.85214 12.1483C3.41556 11.7117 3.06301 11.2232 2.79317 10.7028C2.66913 10.4635 2.39969 10.329 2.13937 10.3987C1.82795 10.4821 1.65738 10.8194 1.80178 11.1077C2.1261 11.7551 2.55778 12.3624 3.09789 12.9026C5.80564 15.6103 10.1955 15.6101 12.9031 12.9026C15.6107 10.195 15.6109 5.80509 12.9031 3.09734C12.363 2.55723 11.7556 2.12555 11.1082 1.80123C10.82 1.65683 10.4827 1.8274 10.3993 2.13882Z"
|
|
39
|
+
}), /* @__PURE__ */ React.createElement("path", {
|
|
40
|
+
className: styles["sapphire-spinner__accent"],
|
|
41
|
+
d: "M1.72661 8.85304C1.98694 8.78329 2.15316 8.53215 2.14111 8.26291C2.07002 6.67514 2.63971 5.06425 3.85203 3.85193C5.06452 2.63944 6.67527 2.06989 8.26302 2.14101C8.53225 2.15306 8.78337 1.98683 8.85309 1.7265C8.93661 1.41464 8.72921 1.09798 8.4069 1.07913C6.49959 0.96764 4.55516 1.6403 3.09778 3.09768C1.64062 4.55485 0.967813 6.49934 1.07909 8.40676C1.0979 8.72916 1.41467 8.93663 1.72661 8.85304Z"
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { Spinner };
|
|
46
|
+
//# sourceMappingURL=Spinner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Spinner.js","sources":["../../../../src/Spinner/src/Spinner.tsx"],"sourcesContent":["import React from 'react';\nimport clsx from 'clsx';\nimport styles from '@danske/sapphire-css/components/spinner/spinner.module.css';\nimport {\n useThemeCheck,\n SapphireStyleProps,\n useSapphireStyleProps,\n} from '@danske/sapphire-react';\n\nexport type SpinnerProps = {\n /**\n * @default 'm'\n */\n size?: 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl';\n} & SapphireStyleProps &\n ({ 'aria-labelledby': string } | { 'aria-label': string });\n\n/**\n * Animated element that show that some data is still loading or some process\n * is in progress. The hidden label is required for accessibility reasons.\n */\nexport const Spinner = ({\n size = 'm',\n ...props\n}: SpinnerProps): JSX.Element => {\n useThemeCheck();\n\n const { styleProps } = useSapphireStyleProps(props);\n\n /**\n * There is @react-aria/progress but because we only have a \"indeterminate\"\n * spinner, we only need one prop, the 'role' attr.\n * Therefore, it seemed like an overkill to use react-aria here.\n */\n\n return (\n <svg\n role=\"progressbar\"\n aria-label={'aria-label' in props ? props['aria-label'] : undefined}\n aria-labelledby={\n 'aria-labelledby' in props ? props['aria-labelledby'] : undefined\n }\n className={clsx(\n styleProps.className,\n styles['sapphire-spinner'],\n size !== 'm' ? styles[`sapphire-spinner--${size}` as const] : ''\n )}\n style={styleProps.style}\n viewBox=\"0 0 16 16\"\n >\n <path\n className={styles['sapphire-spinner__track']}\n d=\"M10.3993 2.13882C10.3295 2.39914 10.4641 2.66858 10.7034 2.79263C11.2238 3.06246 11.7123 3.41501 12.1489 3.85159C14.4401 6.14281 14.4399 9.85728 12.1489 12.1483C9.85783 14.4393 6.14335 14.4395 3.85214 12.1483C3.41556 11.7117 3.06301 11.2232 2.79317 10.7028C2.66913 10.4635 2.39969 10.329 2.13937 10.3987C1.82795 10.4821 1.65738 10.8194 1.80178 11.1077C2.1261 11.7551 2.55778 12.3624 3.09789 12.9026C5.80564 15.6103 10.1955 15.6101 12.9031 12.9026C15.6107 10.195 15.6109 5.80509 12.9031 3.09734C12.363 2.55723 11.7556 2.12555 11.1082 1.80123C10.82 1.65683 10.4827 1.8274 10.3993 2.13882Z\"\n />\n <path\n className={styles['sapphire-spinner__accent']}\n d=\"M1.72661 8.85304C1.98694 8.78329 2.15316 8.53215 2.14111 8.26291C2.07002 6.67514 2.63971 5.06425 3.85203 3.85193C5.06452 2.63944 6.67527 2.06989 8.26302 2.14101C8.53225 2.15306 8.78337 1.98683 8.85309 1.7265C8.93661 1.41464 8.72921 1.09798 8.4069 1.07913C6.49959 0.96764 4.55516 1.6403 3.09778 3.09768C1.64062 4.55485 0.967813 6.49934 1.07909 8.40676C1.0979 8.72916 1.41467 8.93663 1.72661 8.85304Z\"\n />\n </svg>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBa,MAAA,OAAA,GAAU,CAAC,EAGS,KAAA;AAHT,EACtB,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAO,IAAA,GAAA,GAAA;AAAA,GADe,GAAA,EAAA,EAEnB,kBAFmB,EAEnB,EAAA;AAAA,IADH,MAAA;AAAA,GAAA,CAAA,CAAA;AAGA,EAAA,aAAA,EAAA,CAAA;AAEA,EAAM,MAAA,EAAE,eAAe,qBAAsB,CAAA,KAAA,CAAA,CAAA;AAQ7C,EAAA,2CACG,KAAD,EAAA;AAAA,IACE,IAAK,EAAA,aAAA;AAAA,IACL,YAAY,EAAA,YAAA,IAAgB,KAAQ,GAAA,KAAA,CAAM,YAAgB,CAAA,GAAA,KAAA,CAAA;AAAA,IAC1D,iBACE,EAAA,iBAAA,IAAqB,KAAQ,GAAA,KAAA,CAAM,iBAAqB,CAAA,GAAA,KAAA,CAAA;AAAA,IAE1D,SAAA,EAAW,IACT,CAAA,UAAA,CAAW,SACX,EAAA,MAAA,CAAO,qBACP,IAAS,KAAA,GAAA,GAAM,MAAO,CAAA,CAAA,kBAAA,EAAqB,IAAmB,CAAA,CAAA,CAAA,GAAA,EAAA,CAAA;AAAA,IAEhE,OAAO,UAAW,CAAA,KAAA;AAAA,IAClB,OAAQ,EAAA,WAAA;AAAA,GAAA,sCAEP,MAAD,EAAA;AAAA,IACE,WAAW,MAAO,CAAA,yBAAA,CAAA;AAAA,IAClB,CAAE,EAAA,4kBAAA;AAAA,GAAA,CAAA,sCAEH,MAAD,EAAA;AAAA,IACE,WAAW,MAAO,CAAA,0BAAA,CAAA;AAAA,IAClB,CAAE,EAAA,gZAAA;AAAA,GAAA,CAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useToast } from '@react-aria/toast';
|
|
4
|
+
import { useSapphireStyleProps, IconButton } from '@danske/sapphire-react';
|
|
5
|
+
import styles from '@danske/sapphire-css/components/toast/toast.module.css';
|
|
6
|
+
import { Close } from '@danske/sapphire-icons/react';
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __defProps = Object.defineProperties;
|
|
10
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
11
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
14
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __spreadValues = (a, b) => {
|
|
16
|
+
for (var prop in b || (b = {}))
|
|
17
|
+
if (__hasOwnProp.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
if (__getOwnPropSymbols)
|
|
20
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
21
|
+
if (__propIsEnum.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
var __objRest = (source, exclude) => {
|
|
28
|
+
var target = {};
|
|
29
|
+
for (var prop in source)
|
|
30
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
if (source != null && __getOwnPropSymbols)
|
|
33
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
34
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
35
|
+
target[prop] = source[prop];
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
};
|
|
39
|
+
const Toast = (_a) => {
|
|
40
|
+
var _b = _a, { state } = _b, props = __objRest(_b, ["state"]);
|
|
41
|
+
const {
|
|
42
|
+
styleProps: { style, className }
|
|
43
|
+
} = useSapphireStyleProps(props);
|
|
44
|
+
const ref = useRef(null);
|
|
45
|
+
const { toastProps, titleProps, closeButtonProps } = useToast(props, state, ref);
|
|
46
|
+
return /* @__PURE__ */ React.createElement("div", __spreadProps(__spreadValues({}, toastProps), {
|
|
47
|
+
className: clsx(styles["sapphire-toast"], props.toast.animation ? styles[`sapphire-toast--${props.toast.animation}`] : {}, className),
|
|
48
|
+
style,
|
|
49
|
+
ref,
|
|
50
|
+
onAnimationEnd: () => {
|
|
51
|
+
if (props.toast.animation === "exiting") {
|
|
52
|
+
state.remove(props.toast.key);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
56
|
+
className: clsx(styles["sapphire-toast__content"])
|
|
57
|
+
}, /* @__PURE__ */ React.createElement("div", __spreadValues({}, titleProps), props.toast.content), /* @__PURE__ */ React.createElement(IconButton, __spreadProps(__spreadValues({}, closeButtonProps), {
|
|
58
|
+
"aria-label": "Close",
|
|
59
|
+
size: "small",
|
|
60
|
+
variant: "tertiary",
|
|
61
|
+
appearance: "ghost"
|
|
62
|
+
}), /* @__PURE__ */ React.createElement(Close, null))));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { Toast };
|
|
66
|
+
//# sourceMappingURL=Toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.js","sources":["../../../../src/Toast/src/Toast.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport clsx from 'clsx';\nimport { AriaToastProps, useToast } from '@react-aria/toast';\nimport {\n SapphireStyleProps,\n useSapphireStyleProps,\n IconButton,\n} from '@danske/sapphire-react';\n\nimport styles from '@danske/sapphire-css/components/toast/toast.module.css';\nimport { ToastState } from '@react-stately/toast';\nimport { Close } from '@danske/sapphire-icons/react';\n\nexport type ToastProps<T> = AriaToastProps<T> &\n SapphireStyleProps & {\n state: ToastState<T>;\n };\n\nexport const Toast = <T,>({ state, ...props }: ToastProps<T>) => {\n const {\n styleProps: { style, className },\n } = useSapphireStyleProps(props);\n\n const ref = useRef(null);\n const { toastProps, titleProps, closeButtonProps } = useToast(\n props,\n state,\n ref\n );\n\n return (\n <div\n {...toastProps}\n className={clsx(\n styles['sapphire-toast'],\n props.toast.animation\n ? styles[`sapphire-toast--${props.toast.animation}`]\n : {},\n className\n )}\n style={style}\n ref={ref}\n onAnimationEnd={() => {\n // Remove the toast when the exiting animation completes.\n if (props.toast.animation === 'exiting') {\n state.remove(props.toast.key);\n }\n }}\n >\n <div className={clsx(styles['sapphire-toast__content'])}>\n <div {...titleProps}>{props.toast.content}</div>\n <IconButton\n {...closeButtonProps}\n aria-label=\"Close\"\n size=\"small\"\n variant=\"tertiary\"\n appearance=\"ghost\"\n >\n <Close />\n </IconButton>\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBa,MAAA,KAAA,GAAQ,CAAK,EAAuC,KAAA;AAAvC,EAAA,IAAA,EAAA,GAAA,EAAA,EAAE,EAAF,KAAA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,gBADN,CAAA,EAAA;AAAA,IAEE,YAAW,EAAA,OAAA;AAAA,IACX,IAAK,EAAA,OAAA;AAAA,IACL,OAAQ,EAAA,UAAA;AAAA,IACR,UAAW,EAAA,OAAA;AAAA,GAAA,CAAA,sCAEV,KAAD,EAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useThemeCheck } from '@danske/sapphire-react';
|
|
3
|
+
import { useToastState } from '@react-stately/toast';
|
|
4
|
+
import { ToastRegion } from './ToastRegion.js';
|
|
5
|
+
import { ToastContext } from './context.js';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __objRest = (source, exclude) => {
|
|
27
|
+
var target = {};
|
|
28
|
+
for (var prop in source)
|
|
29
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
+
target[prop] = source[prop];
|
|
31
|
+
if (source != null && __getOwnPropSymbols)
|
|
32
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
const ToastProvider = (_a) => {
|
|
39
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
40
|
+
useThemeCheck();
|
|
41
|
+
const state = useToastState({
|
|
42
|
+
maxVisibleToasts: 1,
|
|
43
|
+
hasExitAnimation: true
|
|
44
|
+
});
|
|
45
|
+
return /* @__PURE__ */ React.createElement(ToastContext.Provider, {
|
|
46
|
+
value: state
|
|
47
|
+
}, children, state.visibleToasts.length > 0 && /* @__PURE__ */ React.createElement(ToastRegion, __spreadProps(__spreadValues({}, props), {
|
|
48
|
+
state
|
|
49
|
+
})));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { ToastProvider };
|
|
53
|
+
//# sourceMappingURL=ToastProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToastProvider.js","sources":["../../../../src/Toast/src/ToastProvider.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport { useThemeCheck } from '@danske/sapphire-react';\n\nimport { useToastState } from '@react-stately/toast';\nimport { ToastRegionProps, ToastRegion } from './ToastRegion';\nimport { ToastContext } from './context';\n\nexport type ToastProviderProps = Omit<ToastRegionProps<ReactNode>, 'state'> & {\n children: React.ReactNode;\n};\n\n/**\n * Sapphire toast provider.\n * Render this at the root of your app.\n */\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps) => {\n useThemeCheck();\n\n const state = useToastState<ReactNode>({\n maxVisibleToasts: 1,\n hasExitAnimation: true,\n });\n\n return (\n <ToastContext.Provider value={state}>\n {children}\n {state.visibleToasts.length > 0 && (\n <ToastRegion {...props} state={state} />\n )}\n </ToastContext.Provider>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAea,MAAA,aAAA,GAAgB,CAAC,EAA+C,KAAA;AAA/C,EAAA,IAAA,EAAA,GAAA,EAAA,EAAE,EAAF,QAAA,EAAA,GAAA,EAAA,EAAe,KAAf,GAAA,SAAA,CAAA,EAAA,EAAe,CAAb,UAAA,CAAA,CAAA,CAAA;AAC9B,EAAA,aAAA,EAAA,CAAA;AAEA,EAAA,MAAM,QAAQ,aAAyB,CAAA;AAAA,IACrC,gBAAkB,EAAA,CAAA;AAAA,IAClB,gBAAkB,EAAA,IAAA;AAAA,GAAA,CAAA,CAAA;AAGpB,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,aAAa,QAAd,EAAA;AAAA,IAAuB,KAAO,EAAA,KAAA;AAAA,GAC3B,EAAA,QAAA,EACA,MAAM,aAAc,CAAA,MAAA,GAAS,qBAC3B,KAAA,CAAA,aAAA,CAAA,WAAA,EAAD,iCAAiB,KAAjB,CAAA,EAAA;AAAA,IAAwB,KAAA;AAAA,GAAA,CAAA,CAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { useToastRegion } from '@react-aria/toast';
|
|
3
|
+
import { SapphireOverlayContainer, ThemeRoot } from '@danske/sapphire-react';
|
|
4
|
+
import styles from '@danske/sapphire-css/components/toast/toast.module.css';
|
|
5
|
+
import { Toast } from './Toast.js';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __objRest = (source, exclude) => {
|
|
27
|
+
var target = {};
|
|
28
|
+
for (var prop in source)
|
|
29
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
+
target[prop] = source[prop];
|
|
31
|
+
if (source != null && __getOwnPropSymbols)
|
|
32
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
const ToastRegion = (_a) => {
|
|
39
|
+
var _b = _a, { state } = _b, props = __objRest(_b, ["state"]);
|
|
40
|
+
const ref = useRef(null);
|
|
41
|
+
const { regionProps } = useToastRegion(props, state, ref);
|
|
42
|
+
return /* @__PURE__ */ React.createElement(SapphireOverlayContainer, null, /* @__PURE__ */ React.createElement(ThemeRoot, {
|
|
43
|
+
contrast: true
|
|
44
|
+
}, /* @__PURE__ */ React.createElement("div", __spreadProps(__spreadValues({}, regionProps), {
|
|
45
|
+
ref,
|
|
46
|
+
className: styles["sapphire-toast-container"],
|
|
47
|
+
style: { zIndex: 200 }
|
|
48
|
+
}), state.visibleToasts.map((toast) => /* @__PURE__ */ React.createElement(Toast, __spreadProps(__spreadValues({}, props), {
|
|
49
|
+
key: toast.key,
|
|
50
|
+
toast,
|
|
51
|
+
state
|
|
52
|
+
}))))));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { ToastRegion };
|
|
56
|
+
//# sourceMappingURL=ToastRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToastRegion.js","sources":["../../../../src/Toast/src/ToastRegion.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { AriaToastRegionProps, useToastRegion } from '@react-aria/toast';\nimport {\n SapphireOverlayContainer,\n SapphireStyleProps,\n ThemeRoot,\n} from '@danske/sapphire-react';\n\nimport styles from '@danske/sapphire-css/components/toast/toast.module.css';\nimport { ToastState } from '@react-stately/toast';\nimport { Toast } from './Toast';\n\nexport type ToastRegionProps<T> = AriaToastRegionProps &\n SapphireStyleProps & {\n state: ToastState<T>;\n };\n\nexport const ToastRegion = <T,>({ state, ...props }: ToastRegionProps<T>) => {\n const ref = useRef(null);\n const { regionProps } = useToastRegion(props, state, ref);\n\n return (\n <SapphireOverlayContainer>\n <ThemeRoot contrast>\n <div\n {...regionProps}\n ref={ref}\n className={styles['sapphire-toast-container']}\n style={{ zIndex: 200 } /* above overlays from @danske/sapphire-react */}\n >\n {state.visibleToasts.map((toast) => (\n <Toast {...props} key={toast.key} toast={toast} state={state} />\n ))}\n </div>\n </ThemeRoot>\n </SapphireOverlayContainer>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBa,MAAA,WAAA,GAAc,CAAK,EAA6C,KAAA;AAA7C,EAAA,IAAA,EAAA,GAAA,EAAA,EAAE,EAAF,KAAA,EAAA,GAAA,EAAA,EAAY,KAAZ,GAAA,SAAA,CAAA,EAAA,EAAY,CAAV,OAAA,CAAA,CAAA,CAAA;AAChC,EAAA,MAAM,MAAM,MAAO,CAAA,IAAA,CAAA,CAAA;AACnB,EAAA,MAAM,EAAE,WAAA,EAAA,GAAgB,cAAe,CAAA,KAAA,EAAO,KAAO,EAAA,GAAA,CAAA,CAAA;AAErD,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,wBAAA,EAAD,IACE,kBAAA,KAAA,CAAA,aAAA,CAAC,SAAD,EAAA;AAAA,IAAW,QAAQ,EAAA,IAAA;AAAA,GACjB,kBAAA,KAAA,CAAA,aAAA,CAAC,KAAD,EAAA,aAAA,CAAA,cAAA,CAAA,EAAA,EACM,WADN,CAAA,EAAA;AAAA,IAEE,GAAA;AAAA,IACA,WAAW,MAAO,CAAA,0BAAA,CAAA;AAAA,IAClB,KAAA,EAAO,EAAE,MAAQ,EAAA,GAAA,EAAA;AAAA,GAEhB,CAAA,EAAA,KAAA,CAAM,cAAc,GAAI,CAAA,CAAC,0BACvB,KAAA,CAAA,aAAA,CAAA,KAAA,EAAD,iCAAW,KAAX,CAAA,EAAA;AAAA,IAAkB,KAAK,KAAM,CAAA,GAAA;AAAA,IAAK,KAAA;AAAA,IAAc,KAAA;AAAA,GAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
const ToastContext = React.createContext(null);
|
|
4
|
+
const useToastContext = () => {
|
|
5
|
+
const context = useContext(ToastContext);
|
|
6
|
+
return context;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { ToastContext, useToastContext };
|
|
10
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../../../src/Toast/src/context.ts"],"sourcesContent":["import React, { ReactNode, useContext } from 'react';\nimport { ToastState } from '@react-stately/toast';\n\nexport const ToastContext = React.createContext<ToastState<ReactNode> | null>(\n null\n);\n\nexport const useToastContext = () => {\n const context = useContext(ToastContext);\n\n return context;\n};\n"],"names":[],"mappings":";;AAGa,MAAA,YAAA,GAAe,MAAM,aAChC,CAAA,IAAA,EAAA;AAGK,MAAM,kBAAkB,MAAM;AACnC,EAAA,MAAM,UAAU,UAAW,CAAA,YAAA,CAAA,CAAA;AAE3B,EAAO,OAAA,OAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useToastContext } from './context.js';
|
|
2
|
+
|
|
3
|
+
const useShowToast = () => {
|
|
4
|
+
const toastState = useToastContext();
|
|
5
|
+
if (!toastState) {
|
|
6
|
+
throw new Error('"useShowToast" should be used inside a <ToastProvider>.');
|
|
7
|
+
}
|
|
8
|
+
return (content, options) => {
|
|
9
|
+
const { onClose, timeout = 3e3 } = options || {};
|
|
10
|
+
toastState.add(content, { onClose, timeout });
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useShowToast };
|
|
15
|
+
//# sourceMappingURL=useShowToast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useShowToast.js","sources":["../../../../src/Toast/src/useShowToast.ts"],"sourcesContent":["import { ReactNode } from 'react';\nimport { useToastContext } from './context';\n\nexport type ShowToastFn = (\n content: ReactNode,\n options?: ShowToastOptions\n) => void;\n\nexport type ShowToastOptions = {\n /**\n * Handler that is called when the toast is closed, either by the user\n * or after a timeout.\n */\n onClose?: () => void;\n /**\n * A timeout to automatically close the toast after, in milliseconds.\n * Note that if the toast is hovered or interacted with, the timeout is\n * paused.\n *\n * @default 3000\n */\n timeout?: number;\n};\n\nexport const useShowToast = (): ShowToastFn => {\n const toastState = useToastContext();\n\n if (!toastState) {\n throw new Error('\"useShowToast\" should be used inside a <ToastProvider>.');\n }\n\n return (content, options) => {\n const { onClose, timeout = 3000 } = options || {};\n /*\n * NOTE:\n * There is an addition \"priority\" parameter to \".add\".\n * We don't use it now, but we should if we will have different types of\n * toast notifications with different priorities.\n */\n toastState.add(content, { onClose, timeout });\n };\n};\n"],"names":[],"mappings":";;AAwBO,MAAM,eAAe,MAAmB;AAC7C,EAAA,MAAM,UAAa,GAAA,eAAA,EAAA,CAAA;AAEnB,EAAA,IAAI,CAAC,UAAY,EAAA;AACf,IAAA,MAAM,IAAI,KAAM,CAAA,yDAAA,CAAA,CAAA;AAAA,GAAA;AAGlB,EAAO,OAAA,CAAC,SAAS,OAAY,KAAA;AAC3B,IAAA,MAAM,EAAE,OAAA,EAAS,OAAU,GAAA,GAAA,EAAA,GAAS,OAAW,IAAA,EAAA,CAAA;AAO/C,IAAW,UAAA,CAAA,GAAA,CAAI,OAAS,EAAA,EAAE,OAAS,EAAA,OAAA,EAAA,CAAA,CAAA;AAAA,GAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useFocusableRef } from '@react-spectrum/utils';
|
|
3
|
+
import { FocusRing } from '@react-aria/focus';
|
|
4
|
+
import { mergeProps } from '@react-aria/utils';
|
|
5
|
+
import { useToggleButton } from '@react-aria/button';
|
|
6
|
+
import { useHover } from '@react-aria/interactions';
|
|
7
|
+
import { useToggleState } from '@react-stately/toggle';
|
|
8
|
+
import clsx from 'clsx';
|
|
9
|
+
import styles from '@danske/sapphire-css/components/button/button.module.css';
|
|
10
|
+
import { useThemeCheck, useSapphireStyleProps, Icon, usePreventTouchEnd } from '@danske/sapphire-react';
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defProps = Object.defineProperties;
|
|
14
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
15
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
19
|
+
var __spreadValues = (a, b) => {
|
|
20
|
+
for (var prop in b || (b = {}))
|
|
21
|
+
if (__hasOwnProp.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
if (__getOwnPropSymbols)
|
|
24
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
25
|
+
if (__propIsEnum.call(b, prop))
|
|
26
|
+
__defNormalProp(a, prop, b[prop]);
|
|
27
|
+
}
|
|
28
|
+
return a;
|
|
29
|
+
};
|
|
30
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
31
|
+
var __objRest = (source, exclude) => {
|
|
32
|
+
var target = {};
|
|
33
|
+
for (var prop in source)
|
|
34
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
35
|
+
target[prop] = source[prop];
|
|
36
|
+
if (source != null && __getOwnPropSymbols)
|
|
37
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
38
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
39
|
+
target[prop] = source[prop];
|
|
40
|
+
}
|
|
41
|
+
return target;
|
|
42
|
+
};
|
|
43
|
+
const ToggleButton = React.forwardRef(function Button(_a, ref) {
|
|
44
|
+
var _b = _a, {
|
|
45
|
+
iconAlign = "left",
|
|
46
|
+
icon,
|
|
47
|
+
size = "medium"
|
|
48
|
+
} = _b, otherProps = __objRest(_b, [
|
|
49
|
+
"iconAlign",
|
|
50
|
+
"icon",
|
|
51
|
+
"size"
|
|
52
|
+
]);
|
|
53
|
+
useThemeCheck();
|
|
54
|
+
const { autoFocus, isDisabled } = otherProps;
|
|
55
|
+
const domRef = useFocusableRef(ref);
|
|
56
|
+
const { hoverProps, isHovered } = useHover({ isDisabled });
|
|
57
|
+
const { styleProps } = useSapphireStyleProps(otherProps);
|
|
58
|
+
const iconWrapper = icon && /* @__PURE__ */ React.createElement("span", {
|
|
59
|
+
className: clsx(styles["sapphire-button__icon"])
|
|
60
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
61
|
+
size: size === "small" ? "s" : size === "medium" ? "m" : "l"
|
|
62
|
+
}, icon));
|
|
63
|
+
const state = useToggleState(otherProps);
|
|
64
|
+
const { buttonProps, isPressed } = useToggleButton(otherProps, state, domRef);
|
|
65
|
+
usePreventTouchEnd(domRef);
|
|
66
|
+
return /* @__PURE__ */ React.createElement(FocusRing, {
|
|
67
|
+
focusRingClass: clsx(styles["is-focus"]),
|
|
68
|
+
autoFocus
|
|
69
|
+
}, /* @__PURE__ */ React.createElement("button", __spreadProps(__spreadValues({}, mergeProps(buttonProps, hoverProps)), {
|
|
70
|
+
ref: domRef,
|
|
71
|
+
style: __spreadValues({}, styleProps.style),
|
|
72
|
+
className: clsx(styles["sapphire-button"], styles["js-focus"], styles["js-hover"], {
|
|
73
|
+
[styles["is-active"]]: isPressed,
|
|
74
|
+
[styles["is-hover"]]: isHovered,
|
|
75
|
+
[styles["is-disabled"]]: isDisabled,
|
|
76
|
+
[styles["sapphire-button--small"]]: size === "small",
|
|
77
|
+
[styles["sapphire-button--large"]]: size === "large",
|
|
78
|
+
[styles["sapphire-button--with-left-icon"]]: icon && iconAlign === "left",
|
|
79
|
+
[styles["sapphire-button--with-right-icon"]]: icon && iconAlign === "right"
|
|
80
|
+
}, state.isSelected ? styles["sapphire-button--selected"] : styles["sapphire-button--unselected"], styleProps.className)
|
|
81
|
+
}), iconAlign === "left" && iconWrapper, otherProps.children, iconAlign === "right" && iconWrapper));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export { ToggleButton };
|
|
85
|
+
//# sourceMappingURL=ToggleButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToggleButton.js","sources":["../../../../src/ToggleButton/src/ToggleButton.tsx"],"sourcesContent":["import React from 'react';\nimport { useFocusableRef } from '@react-spectrum/utils';\nimport { FocusableRef, PressEvents } from '@react-types/shared';\nimport { FocusRing } from '@react-aria/focus';\nimport { mergeProps } from '@react-aria/utils';\nimport { AriaToggleButtonProps, useToggleButton } from '@react-aria/button';\nimport { useHover } from '@react-aria/interactions';\nimport { useToggleState } from '@react-stately/toggle';\nimport clsx from 'clsx';\n\nimport styles from '@danske/sapphire-css/components/button/button.module.css';\n\nimport {\n SapphireStyleProps,\n useSapphireStyleProps,\n useThemeCheck,\n usePreventTouchEnd,\n Icon,\n} from '@danske/sapphire-react';\n\nexport type SapphireToggleButtonProps = Omit<\n AriaToggleButtonProps<'button'>,\n 'elementType' | 'type'\n> &\n SapphireStyleProps &\n PressEvents & {\n /**\n * @default 'medium'\n */\n size?: 'large' | 'medium' | 'small';\n onChange?: (selected: boolean) => void;\n isSelected?: boolean;\n defaultSelected?: boolean;\n } & (ButtonWithIconProps | ButtonWithoutIconProps);\n\n// TODO: use ButtonWithIconProps and ButtonWithoutIconProps in core, when moved there\nexport type ButtonWithIconProps = {\n /**\n * The icon placed either before or after the `label`, based on `iconAlign` prop.\n * */\n icon: React.ReactNode;\n /**\n * The icon placement relative to the `label`.\n * */\n iconAlign?: 'left' | 'right';\n};\n\nexport type ButtonWithoutIconProps = {\n icon?: never;\n iconAlign?: never;\n};\n\n/**\n * A button with a toggleable `isSelected` state. By default, the selection is toggled when the\n * button is pressed, allowing user to switch between two states or modes.\n */\nexport const ToggleButton = React.forwardRef(function Button(\n {\n iconAlign = 'left',\n icon,\n size = 'medium',\n ...otherProps\n }: SapphireToggleButtonProps,\n ref: FocusableRef<HTMLButtonElement>\n) {\n useThemeCheck();\n\n const { autoFocus, isDisabled } = otherProps;\n const domRef = useFocusableRef<HTMLButtonElement>(ref);\n const { hoverProps, isHovered } = useHover({ isDisabled });\n const { styleProps } = useSapphireStyleProps(otherProps);\n\n const iconWrapper = icon && (\n <span className={clsx(styles['sapphire-button__icon'])}>\n <Icon size={size === 'small' ? 's' : size === 'medium' ? 'm' : 'l'}>\n {icon}\n </Icon>\n </span>\n );\n\n const state = useToggleState(otherProps);\n const { buttonProps, isPressed } = useToggleButton(otherProps, state, domRef);\n usePreventTouchEnd(domRef);\n\n return (\n <FocusRing focusRingClass={clsx(styles['is-focus'])} autoFocus={autoFocus}>\n <button\n {...mergeProps(buttonProps, hoverProps)}\n ref={domRef}\n style={{ ...styleProps.style }}\n className={clsx(\n styles['sapphire-button'],\n styles['js-focus'],\n styles['js-hover'],\n {\n [styles['is-active']]: isPressed,\n [styles['is-hover']]: isHovered,\n [styles['is-disabled']]: isDisabled,\n [styles['sapphire-button--small']]: size === 'small',\n [styles['sapphire-button--large']]: size === 'large',\n [styles['sapphire-button--with-left-icon']]:\n icon && iconAlign === 'left',\n [styles['sapphire-button--with-right-icon']]:\n icon && iconAlign === 'right',\n },\n state.isSelected\n ? styles['sapphire-button--selected']\n : styles['sapphire-button--unselected'],\n styleProps.className\n )}\n >\n {iconAlign === 'left' && iconWrapper}\n {otherProps.children}\n {iconAlign === 'right' && iconWrapper}\n </button>\n </FocusRing>\n );\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDO,MAAM,YAAe,GAAA,KAAA,CAAM,UAAW,CAAA,SAAA,MAAA,CAC3C,IAMA,GACA,EAAA;AAPA,EACE,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAY,SAAA,GAAA,MAAA;AAAA,IACZ,IAAA;AAAA,IACA,IAAO,GAAA,QAAA;AAAA,GAHT,GAAA,EAAA,EAIK,uBAJL,EAIK,EAAA;AAAA,IAHH,WAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,GAAA,CAAA,CAAA;AAKF,EAAA,aAAA,EAAA,CAAA;AAEA,EAAM,MAAA,EAAE,WAAW,UAAe,EAAA,GAAA,UAAA,CAAA;AAClC,EAAA,MAAM,SAAS,eAAmC,CAAA,GAAA,CAAA,CAAA;AAClD,EAAA,MAAM,EAAE,UAAA,EAAY,SAAc,EAAA,GAAA,QAAA,CAAS,EAAE,UAAA,EAAA,CAAA,CAAA;AAC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4BAA4B,IAAS,KAAA,OAAA;AAAA,MAC5C,CAAA,MAAA,CAAO,iCACN,CAAA,GAAA,IAAA,IAAQ,SAAc,KAAA,MAAA;AAAA,MACvB,CAAA,MAAA,CAAO,kCACN,CAAA,GAAA,IAAA,IAAQ,SAAc,KAAA,OAAA;AAAA,KAAA,EAE1B,MAAM,UACF,GAAA,MAAA,CAAO,2BACP,CAAA,GAAA,MAAA,CAAO,gCACX,UAAW,CAAA,SAAA,CAAA;AAAA,GAAA,CAAA,EAGZ,cAAc,MAAU,IAAA,WAAA,EACxB,UAAW,CAAA,QAAA,EACX,cAAc,OAAW,IAAA,WAAA,CAAA,CAAA,CAAA;AAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Heading } from './src/Heading.js';
|
|
2
|
+
import { Subheading } from './src/Subheading.js';
|
|
3
|
+
import { Body } from './src/Body.js';
|
|
4
|
+
import { Caption } from './src/Caption.js';
|
|
5
|
+
|
|
6
|
+
const Typography = {
|
|
7
|
+
Heading,
|
|
8
|
+
Subheading,
|
|
9
|
+
Body,
|
|
10
|
+
Caption
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { Typography };
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/Typography/index.ts"],"sourcesContent":["import { Heading, type TypographyHeadingProps } from './src/Heading';\nimport { Subheading, type TypographySubheadingProps } from './src/Subheading';\nimport { Body, type TypographyBodyProps } from './src/Body';\nimport { Caption, TypographyCaptionProps } from './src/Caption';\nimport { ComponentType } from 'react';\n\nexport const Typography: {\n Heading: ComponentType<TypographyHeadingProps>;\n Subheading: ComponentType<TypographySubheadingProps>;\n Body: ComponentType<TypographyBodyProps>;\n Caption: ComponentType<TypographyCaptionProps>;\n} = {\n Heading,\n Subheading,\n Body,\n Caption,\n};\n\nexport type {\n TypographyHeadingProps,\n TypographySubheadingProps,\n TypographyBodyProps,\n TypographyCaptionProps,\n};\n"],"names":[],"mappings":";;;;;AAMO,MAAM,UAKT,GAAA;AAAA,EACF,OAAA;AAAA,EACA,UAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA;;;;"}
|