@norges-domstoler/dds-components 5.5.0 → 6.0.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/dist/_virtual/_rollupPluginBabelHelpers.js +58 -1
- package/dist/cjs/components/InternalHeader/InternalHeader.styles.d.ts +1 -1
- package/dist/cjs/components/OverflowMenu/OverflowMenu.stories.d.ts +1 -1
- package/dist/cjs/components/RadioButton/RadioButtonGroup.d.ts +31 -2
- package/dist/cjs/components/RadioButton/RadioButtonGroup.stories.d.ts +19 -1
- package/dist/cjs/components/Tabs/Tab.d.ts +0 -5
- package/dist/cjs/components/Tabs/Tabs.context.d.ts +0 -2
- package/dist/cjs/components/Tabs/Tabs.d.ts +4 -4
- package/dist/cjs/components/Tabs/Tabs.stories.d.ts +2 -1
- package/dist/cjs/components/Tabs/Tabs.tokens.d.ts +1 -6
- package/dist/cjs/components/Tooltip/Tooltip.stories.d.ts +1 -1
- package/dist/cjs/hooks/index.d.ts +0 -1
- package/dist/cjs/hooks/useCombinedRefs.d.ts +18 -0
- package/dist/cjs/hooks/useFocusTrap.d.ts +16 -1
- package/dist/cjs/hooks/useMountTransition.d.ts +32 -0
- package/dist/cjs/hooks/useOnClickOutside.d.ts +13 -0
- package/dist/cjs/hooks/useOnKeyDown.d.ts +13 -0
- package/dist/cjs/hooks/useRoveFocus.d.ts +25 -1
- package/dist/cjs/hooks/useScreenSize.d.ts +12 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +284 -68
- package/dist/components/InternalHeader/InternalHeader.styles.d.ts +1 -1
- package/dist/components/OverflowMenu/OverflowMenu.js +3 -3
- package/dist/components/OverflowMenu/OverflowMenu.stories.d.ts +1 -1
- package/dist/components/RadioButton/RadioButtonGroup.d.ts +31 -2
- package/dist/components/RadioButton/RadioButtonGroup.js +24 -19
- package/dist/components/RadioButton/RadioButtonGroup.stories.d.ts +19 -1
- package/dist/components/Tabs/Tab.d.ts +0 -5
- package/dist/components/Tabs/Tab.js +6 -12
- package/dist/components/Tabs/TabList.js +7 -1
- package/dist/components/Tabs/Tabs.context.d.ts +0 -2
- package/dist/components/Tabs/Tabs.context.js +1 -2
- package/dist/components/Tabs/Tabs.d.ts +4 -4
- package/dist/components/Tabs/Tabs.js +10 -7
- package/dist/components/Tabs/Tabs.stories.d.ts +2 -1
- package/dist/components/Tabs/Tabs.tokens.d.ts +1 -6
- package/dist/components/Tabs/Tabs.tokens.js +4 -15
- package/dist/components/Tooltip/Tooltip.stories.d.ts +1 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/useCombinedRefs.d.ts +18 -0
- package/dist/hooks/useCombinedRefs.js +19 -0
- package/dist/hooks/useFocusTrap.d.ts +16 -1
- package/dist/hooks/useFocusTrap.js +15 -0
- package/dist/hooks/useMountTransition.d.ts +32 -0
- package/dist/hooks/useMountTransition.js +33 -0
- package/dist/hooks/useOnClickOutside.d.ts +13 -0
- package/dist/hooks/useOnClickOutside.js +14 -0
- package/dist/hooks/useOnKeyDown.d.ts +13 -0
- package/dist/hooks/useOnKeyDown.js +14 -0
- package/dist/hooks/useRoveFocus.d.ts +25 -1
- package/dist/hooks/useRoveFocus.js +25 -0
- package/dist/hooks/useScreenSize.d.ts +12 -0
- package/dist/hooks/useScreenSize.js +53 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
- package/dist/cjs/hooks/useId.d.ts +0 -1
- package/dist/hooks/useId.d.ts +0 -1
- package/dist/hooks/useId.js +0 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { __rest } from 'tslib';
|
|
3
3
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
-
import { useState, useId } from 'react';
|
|
4
|
+
import { forwardRef, useState, useId } from 'react';
|
|
5
5
|
import styled, { css } from 'styled-components';
|
|
6
6
|
import '../../helpers/Backdrop/Backdrop.js';
|
|
7
7
|
import '../../helpers/Chevron/AnimatedChevronUpDown.styles.js';
|
|
@@ -34,24 +34,25 @@ var Label = styled(Typography).withConfig({
|
|
|
34
34
|
displayName: "RadioButtonGroup__Label",
|
|
35
35
|
componentId: "sc-1xsll60-2"
|
|
36
36
|
})(["padding-left:", ";"], radioButtonGroupTokens.label.spaceLeft);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
direction =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
|
|
38
|
+
var RadioButtonGroupInner = function RadioButtonGroupInner(props, ref) {
|
|
39
|
+
var name = props.name,
|
|
40
|
+
label = props.label,
|
|
41
|
+
groupId = props.groupId,
|
|
42
|
+
errorMessage = props.errorMessage,
|
|
43
|
+
tip = props.tip,
|
|
44
|
+
disabled = props.disabled,
|
|
45
|
+
readOnly = props.readOnly,
|
|
46
|
+
_props$direction = props.direction,
|
|
47
|
+
direction = _props$direction === void 0 ? 'row' : _props$direction,
|
|
48
|
+
value = props.value,
|
|
49
|
+
children = props.children,
|
|
50
|
+
required = props.required,
|
|
51
|
+
onChange = props.onChange,
|
|
52
|
+
id = props.id,
|
|
53
|
+
className = props.className,
|
|
54
|
+
htmlProps = props.htmlProps,
|
|
55
|
+
rest = __rest(props, ["name", "label", "groupId", "errorMessage", "tip", "disabled", "readOnly", "direction", "value", "children", "required", "onChange", "id", "className", "htmlProps"]);
|
|
55
56
|
|
|
56
57
|
var _useState = useState(value),
|
|
57
58
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -80,6 +81,8 @@ var RadioButtonGroup = function RadioButtonGroup(_a) {
|
|
|
80
81
|
onChange: handleChange
|
|
81
82
|
};
|
|
82
83
|
return jsxs(Container, Object.assign({}, getBaseHTMLProps(id, className, htmlProps, rest), {
|
|
84
|
+
ref: ref
|
|
85
|
+
}, {
|
|
83
86
|
children: [jsxs(Label, Object.assign({
|
|
84
87
|
forwardedAs: "span",
|
|
85
88
|
typographyType: "supportingStyleLabel01",
|
|
@@ -110,4 +113,6 @@ var RadioButtonGroup = function RadioButtonGroup(_a) {
|
|
|
110
113
|
}));
|
|
111
114
|
};
|
|
112
115
|
|
|
116
|
+
var RadioButtonGroup = /*#__PURE__*/forwardRef(RadioButtonGroupInner);
|
|
117
|
+
|
|
113
118
|
export { RadioButtonGroup };
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { RadioButtonGroupProps } from '.';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
title: string;
|
|
4
|
-
component: <T extends string | number = string>(
|
|
4
|
+
component: <T extends string | number = string>(props: Pick<Omit<import("react").HTMLAttributes<HTMLDivElement>, "onChange">, "id" | "className"> & {
|
|
5
|
+
name?: string | undefined;
|
|
6
|
+
label?: string | undefined;
|
|
7
|
+
onChange?: ((event: import("react").ChangeEvent<HTMLInputElement>, value: T | undefined) => void) | undefined;
|
|
8
|
+
required?: boolean | undefined;
|
|
9
|
+
errorMessage?: string | undefined;
|
|
10
|
+
tip?: string | undefined;
|
|
11
|
+
disabled?: boolean | undefined;
|
|
12
|
+
readOnly?: boolean | undefined;
|
|
13
|
+
direction?: ("row" | "column") | undefined;
|
|
14
|
+
value?: T | undefined;
|
|
15
|
+
groupId?: string | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
children?: import("react").ReactNode;
|
|
18
|
+
} & {
|
|
19
|
+
htmlProps?: Omit<import("react").HTMLAttributes<HTMLDivElement>, "onChange"> | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
ref?: import("react").Ref<HTMLDivElement> | undefined;
|
|
22
|
+
}) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
5
23
|
argTypes: {
|
|
6
24
|
label: {
|
|
7
25
|
control: {
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { ButtonHTMLAttributes, Dispatch, SetStateAction } from 'react';
|
|
2
2
|
import { BaseComponentPropsWithChildren } from '../../types';
|
|
3
|
-
import { Property } from 'csstype';
|
|
4
3
|
import { SvgIcon } from '../../icons/utils';
|
|
5
4
|
export declare type TabProps = BaseComponentPropsWithChildren<HTMLButtonElement, {
|
|
6
5
|
/**Spesifiserer om fanen er aktiv. */
|
|
7
6
|
active?: boolean;
|
|
8
7
|
/** Ikon. */
|
|
9
8
|
icon?: SvgIcon;
|
|
10
|
-
/** Custom bredde for enkel fane. */
|
|
11
|
-
width?: Property.Width;
|
|
12
9
|
/** Spesifiserer om `<Tab />` skal ha fokus. **OBS!** settes automatisk av forelder.*/
|
|
13
10
|
focus?: boolean;
|
|
14
11
|
/** Callback som setter fokus. **OBS!** settes automatisk av forelder.*/
|
|
@@ -21,8 +18,6 @@ export declare const Tab: import("react").ForwardRefExoticComponent<Pick<Omit<Bu
|
|
|
21
18
|
active?: boolean | undefined;
|
|
22
19
|
/** Ikon. */
|
|
23
20
|
icon?: SvgIcon | undefined;
|
|
24
|
-
/** Custom bredde for enkel fane. */
|
|
25
|
-
width?: Property.Width<0 | (string & {})> | undefined;
|
|
26
21
|
/** Spesifiserer om `<Tab />` skal ha fokus. **OBS!** settes automatisk av forelder.*/
|
|
27
22
|
focus?: boolean | undefined;
|
|
28
23
|
/** Callback som setter fokus. **OBS!** settes automatisk av forelder.*/
|
|
@@ -19,20 +19,16 @@ import '../../helpers/styling/selection.js';
|
|
|
19
19
|
var Button = styled.button.withConfig({
|
|
20
20
|
displayName: "Tab__Button",
|
|
21
21
|
componentId: "sc-1dd8soq-0"
|
|
22
|
-
})(["@media (prefers-reduced-motion:no-preference){transition:box-shadow 0.2s,border-bottom 0.2s,color 0.2s,", ";}", "
|
|
23
|
-
var
|
|
24
|
-
return width;
|
|
25
|
-
}, function (_ref2) {
|
|
26
|
-
var direction = _ref2.direction;
|
|
22
|
+
})(["@media (prefers-reduced-motion:no-preference){transition:box-shadow 0.2s,border-bottom 0.2s,color 0.2s,", ";}", " ", ";", " &:focus-visible{", "}&:hover{", "}"], focusVisibleTransitionValue, tabsTokens.tab.base, function (_ref) {
|
|
23
|
+
var direction = _ref.direction;
|
|
27
24
|
return tabsTokens.tab.direction[direction].base;
|
|
28
|
-
}, function (
|
|
29
|
-
var active =
|
|
25
|
+
}, function (_ref2) {
|
|
26
|
+
var active = _ref2.active;
|
|
30
27
|
return active && css(["", ""], tabsTokens.tab.active.base);
|
|
31
28
|
}, tabsTokens.tab.focus.base, tabsTokens.tab.hover.base);
|
|
32
29
|
var Tab = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
33
30
|
var _props$active = props.active,
|
|
34
31
|
active = _props$active === void 0 ? false : _props$active,
|
|
35
|
-
width = props.width,
|
|
36
32
|
icon = props.icon,
|
|
37
33
|
children = props.children,
|
|
38
34
|
focus = props.focus,
|
|
@@ -43,7 +39,7 @@ var Tab = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
43
39
|
id = props.id,
|
|
44
40
|
className = props.className,
|
|
45
41
|
htmlProps = props.htmlProps,
|
|
46
|
-
rest = __rest(props, ["active", "
|
|
42
|
+
rest = __rest(props, ["active", "icon", "children", "focus", "setFocus", "index", "onClick", "onKeyDown", "id", "className", "htmlProps"]);
|
|
47
43
|
|
|
48
44
|
var itemRef = useRef(null);
|
|
49
45
|
var combinedRef = useCombinedRef(ref, itemRef);
|
|
@@ -51,8 +47,7 @@ var Tab = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
51
47
|
var _useTabsContext = useTabsContext(),
|
|
52
48
|
tabPanelsRef = _useTabsContext.tabPanelsRef,
|
|
53
49
|
setHasTabFocus = _useTabsContext.setHasTabFocus,
|
|
54
|
-
tabContentDirection = _useTabsContext.tabContentDirection
|
|
55
|
-
tabWidth = _useTabsContext.tabWidth;
|
|
50
|
+
tabContentDirection = _useTabsContext.tabContentDirection;
|
|
56
51
|
|
|
57
52
|
useEffect(function () {
|
|
58
53
|
var _a;
|
|
@@ -89,7 +84,6 @@ var Tab = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
89
84
|
'aria-selected': active,
|
|
90
85
|
role: 'tab',
|
|
91
86
|
active: active,
|
|
92
|
-
width: width !== null && width !== void 0 ? width : tabWidth,
|
|
93
87
|
direction: tabContentDirection,
|
|
94
88
|
onClick: handleOnClick,
|
|
95
89
|
onKeyDown: handleOnKeyDown,
|
|
@@ -14,11 +14,17 @@ import { useTabsContext } from './Tabs.context.js';
|
|
|
14
14
|
import '../ScrollableContainer/Scrollbar.js';
|
|
15
15
|
import '../ScrollableContainer/ScrollableContainer.js';
|
|
16
16
|
import { scrollbarStyling } from '../ScrollableContainer/scrollbarStyling.js';
|
|
17
|
+
import { focusVisibleTransitionValue, focusVisible } from '../../helpers/styling/focusVisible.js';
|
|
18
|
+
import '../../helpers/styling/hover.js';
|
|
19
|
+
import '../../helpers/styling/focus.js';
|
|
20
|
+
import '../../helpers/styling/danger.js';
|
|
21
|
+
import '../../helpers/styling/selection.js';
|
|
17
22
|
|
|
23
|
+
var tabList = tabsTokens.tabList;
|
|
18
24
|
var TabRow = styled.div.withConfig({
|
|
19
25
|
displayName: "TabList__TabRow",
|
|
20
26
|
componentId: "sc-1ldr0lz-0"
|
|
21
|
-
})(["", "
|
|
27
|
+
})(["border-bottom:", ";display:grid;grid-auto-flow:column;grid-auto-columns:1fr;overflow-x:auto;", " ", " scroll-snap-type:x mandatory;@media (prefers-reduced-motion:no-preference){scroll-behavior:smooth;transition:", ";}&:focus-visible{", "}&:focus-visible button{outline:none;}"], tabList.borderBottom, scrollbarStyling.webkit, scrollbarStyling.firefox, focusVisibleTransitionValue, focusVisible);
|
|
22
28
|
var TabList = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
23
29
|
var children = _a.children,
|
|
24
30
|
id = _a.id,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { Direction } from '../../types';
|
|
3
|
-
import { Property } from 'csstype';
|
|
4
3
|
declare type Tabs = {
|
|
5
4
|
activeTab: number;
|
|
6
5
|
tabsId: string;
|
|
@@ -10,7 +9,6 @@ declare type Tabs = {
|
|
|
10
9
|
hasTabFocus: boolean;
|
|
11
10
|
setHasTabFocus: (hasFocus: boolean) => void;
|
|
12
11
|
tabContentDirection: Direction;
|
|
13
|
-
tabWidth: Property.Width;
|
|
14
12
|
};
|
|
15
13
|
export declare const TabsContext: import("react").Context<Tabs>;
|
|
16
14
|
export declare const useTabsContext: () => Tabs;
|
|
@@ -12,8 +12,7 @@ var TabsContext = /*#__PURE__*/createContext({
|
|
|
12
12
|
setHasTabFocus: function setHasTabFocus() {
|
|
13
13
|
return null;
|
|
14
14
|
},
|
|
15
|
-
tabContentDirection: 'row'
|
|
16
|
-
tabWidth: '150px'
|
|
15
|
+
tabContentDirection: 'row'
|
|
17
16
|
});
|
|
18
17
|
var useTabsContext = function useTabsContext() {
|
|
19
18
|
return useContext(TabsContext);
|
|
@@ -8,8 +8,8 @@ export declare type TabsProps = BaseComponentPropsWithChildren<HTMLDivElement, {
|
|
|
8
8
|
onChange?: (index: number) => void;
|
|
9
9
|
/** Retningen ikon og tekst vises i `<Tab />`-elementer. */
|
|
10
10
|
tabContentDirection?: Direction;
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**Bredde for hele komponenten. */
|
|
12
|
+
width?: Property.Width;
|
|
13
13
|
}, Omit<HTMLAttributes<HTMLDivElement>, 'onChange'>>;
|
|
14
14
|
export declare const Tabs: import("react").ForwardRefExoticComponent<Pick<Omit<HTMLAttributes<HTMLDivElement>, "onChange">, "className" | "id"> & {
|
|
15
15
|
/** Indeksen til den aktive fanen. **OBS!** Ved å sette denne vil brukere aldri kunne endre tab uten at du også registrerer en `onChange`-lytter for å ta vare på aktiv tab utenfor komponenten. */
|
|
@@ -18,8 +18,8 @@ export declare const Tabs: import("react").ForwardRefExoticComponent<Pick<Omit<H
|
|
|
18
18
|
onChange?: ((index: number) => void) | undefined;
|
|
19
19
|
/** Retningen ikon og tekst vises i `<Tab />`-elementer. */
|
|
20
20
|
tabContentDirection?: Direction | undefined;
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**Bredde for hele komponenten. */
|
|
22
|
+
width?: Property.Width<0 | (string & {})> | undefined;
|
|
23
23
|
} & {
|
|
24
24
|
children?: import("react").ReactNode;
|
|
25
25
|
} & {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { __rest } from 'tslib';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import styled, { css } from 'styled-components';
|
|
4
5
|
import { forwardRef, useId, useState, useRef, useEffect } from 'react';
|
|
5
|
-
import styled from 'styled-components';
|
|
6
6
|
import { getBaseHTMLProps } from '../../types/BaseComponentProps.js';
|
|
7
7
|
import { TabsContext } from './Tabs.context.js';
|
|
8
8
|
|
|
9
9
|
var Container = styled.div.withConfig({
|
|
10
10
|
displayName: "Tabs__Container",
|
|
11
11
|
componentId: "sc-7ta5g2-0"
|
|
12
|
-
})([""])
|
|
12
|
+
})(["", ";"], function (_ref) {
|
|
13
|
+
var width = _ref.width;
|
|
14
|
+
return width && css(["width:", ";"], width);
|
|
15
|
+
});
|
|
13
16
|
var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
14
17
|
var id = props.id,
|
|
15
18
|
_props$activeTab = props.activeTab,
|
|
@@ -17,12 +20,11 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
17
20
|
onChange = props.onChange,
|
|
18
21
|
_props$tabContentDire = props.tabContentDirection,
|
|
19
22
|
tabContentDirection = _props$tabContentDire === void 0 ? 'row' : _props$tabContentDire,
|
|
20
|
-
|
|
21
|
-
tabWidth = _props$tabWidth === void 0 ? '150px' : _props$tabWidth,
|
|
23
|
+
width = props.width,
|
|
22
24
|
children = props.children,
|
|
23
25
|
className = props.className,
|
|
24
26
|
htmlProps = props.htmlProps,
|
|
25
|
-
rest = __rest(props, ["id", "activeTab", "onChange", "tabContentDirection", "
|
|
27
|
+
rest = __rest(props, ["id", "activeTab", "onChange", "tabContentDirection", "width", "children", "className", "htmlProps"]);
|
|
26
28
|
|
|
27
29
|
var generatedId = useId();
|
|
28
30
|
var uniqueId = id !== null && id !== void 0 ? id : "".concat(generatedId, "-tabs");
|
|
@@ -62,11 +64,12 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
62
64
|
tabPanelsRef: tabPanelsRef,
|
|
63
65
|
hasTabFocus: hasTabFocus,
|
|
64
66
|
setHasTabFocus: setHasTabFocus,
|
|
65
|
-
tabContentDirection: tabContentDirection
|
|
66
|
-
tabWidth: tabWidth
|
|
67
|
+
tabContentDirection: tabContentDirection
|
|
67
68
|
}
|
|
68
69
|
}, {
|
|
69
70
|
children: jsx(Container, Object.assign({}, containerProps, {
|
|
71
|
+
width: width
|
|
72
|
+
}, {
|
|
70
73
|
children: children
|
|
71
74
|
}))
|
|
72
75
|
}));
|
|
@@ -6,5 +6,6 @@ export declare const Overview: Story<TabsProps>;
|
|
|
6
6
|
export declare const Default: Story<TabsProps>;
|
|
7
7
|
export declare const WithIcon: Story<TabsProps>;
|
|
8
8
|
export declare const ActiveTab: Story<TabsProps>;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const WithWidth: Story<TabsProps>;
|
|
10
|
+
export declare const TabLongNames: Story<TabsProps>;
|
|
10
11
|
export declare const ManyTabs: Story<TabsProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ddsBaseTokens } from '@norges-domstoler/dds-design-tokens';
|
|
2
2
|
import { removeButtonStyling } from '../../helpers/styling/removeButtonStyling.js';
|
|
3
3
|
import 'styled-components';
|
|
4
|
-
import {
|
|
4
|
+
import { focusVisible } from '../../helpers/styling/focusVisible.js';
|
|
5
5
|
import '../../helpers/styling/hover.js';
|
|
6
6
|
import '../../helpers/styling/focus.js';
|
|
7
7
|
import '../../helpers/styling/danger.js';
|
|
@@ -10,15 +10,9 @@ import '../../helpers/styling/selection.js';
|
|
|
10
10
|
var Border = ddsBaseTokens.border,
|
|
11
11
|
Spacing = ddsBaseTokens.spacing,
|
|
12
12
|
Colors = ddsBaseTokens.colors;
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
transition: focusVisibleTransitionValue
|
|
16
|
-
},
|
|
17
|
-
display: 'flex',
|
|
18
|
-
borderBottom: "".concat(Border.BordersDdsBorderStyleLightStrokeWeight, " solid ").concat(Border.BordersDdsBorderStyleLightStroke),
|
|
19
|
-
overflowX: 'auto'
|
|
13
|
+
var tabList = {
|
|
14
|
+
borderBottom: "".concat(Border.BordersDdsBorderStyleLightStrokeWeight, " solid ").concat(Border.BordersDdsBorderStyleLightStroke)
|
|
20
15
|
};
|
|
21
|
-
var tabListFocusBase = Object.assign({}, focusVisible);
|
|
22
16
|
var tabBase = Object.assign(Object.assign({}, removeButtonStyling), {
|
|
23
17
|
display: 'flex',
|
|
24
18
|
alignItems: 'center',
|
|
@@ -61,12 +55,7 @@ var tabPanelBase = {
|
|
|
61
55
|
};
|
|
62
56
|
var tabPanelFocusVisibleBase = Object.assign({}, focusVisible);
|
|
63
57
|
var tabsTokens = {
|
|
64
|
-
tabList:
|
|
65
|
-
base: tabListBase,
|
|
66
|
-
focus: {
|
|
67
|
-
base: tabListFocusBase
|
|
68
|
-
}
|
|
69
|
-
},
|
|
58
|
+
tabList: tabList,
|
|
70
59
|
tab: {
|
|
71
60
|
base: tabBase,
|
|
72
61
|
direction: {
|
|
@@ -3,7 +3,7 @@ declare const _default: {
|
|
|
3
3
|
title: string;
|
|
4
4
|
component: import("react").ForwardRefExoticComponent<Pick<Omit<import("react").HTMLAttributes<HTMLDivElement>, "children" | "style" | "onMouseLeave" | "onMouseOver">, "id" | "className"> & {
|
|
5
5
|
text: string;
|
|
6
|
-
placement?: import("
|
|
6
|
+
placement?: import("../..").Placement | undefined;
|
|
7
7
|
children: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> & import("react").RefAttributes<HTMLElement>;
|
|
8
8
|
delay?: number | undefined;
|
|
9
9
|
tooltipId?: string | undefined;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
import type { RefCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Kombinerer refs for et element.
|
|
4
|
+
* Eksempel på bruk:
|
|
5
|
+
* ```
|
|
6
|
+
* const MyComponent = forwardRef<HTMLDivElement, Props>((props, ref) => {
|
|
7
|
+
*
|
|
8
|
+
* const itemRef = useRef<HTMLDivElement>(null);
|
|
9
|
+
* const combinedRef = useCombinedRef(ref, itemRef);
|
|
10
|
+
*
|
|
11
|
+
* return <div ref={combinedRef}>innhold</div>
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
* @param refs array med refs.
|
|
15
|
+
* @template T elementet som refereres til.
|
|
16
|
+
* @returns callback med kombinerte refs.
|
|
17
|
+
*
|
|
18
|
+
* {@link useCombinedRef}
|
|
19
|
+
*/
|
|
2
20
|
export declare function useCombinedRef<T>(...refs: React.Ref<T>[]): RefCallback<T>;
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Kombinerer refs for et element.
|
|
6
|
+
* Eksempel på bruk:
|
|
7
|
+
* ```
|
|
8
|
+
* const MyComponent = forwardRef<HTMLDivElement, Props>((props, ref) => {
|
|
9
|
+
*
|
|
10
|
+
* const itemRef = useRef<HTMLDivElement>(null);
|
|
11
|
+
* const combinedRef = useCombinedRef(ref, itemRef);
|
|
12
|
+
*
|
|
13
|
+
* return <div ref={combinedRef}>innhold</div>
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
* @param refs array med refs.
|
|
17
|
+
* @template T elementet som refereres til.
|
|
18
|
+
* @returns callback med kombinerte refs.
|
|
19
|
+
*
|
|
20
|
+
* {@link useCombinedRef}
|
|
21
|
+
*/
|
|
22
|
+
|
|
4
23
|
function useCombinedRef() {
|
|
5
24
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6
25
|
refs[_key] = arguments[_key];
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Fanger fokus i en loop inni et element. Typisk bruk:
|
|
4
|
+
* ```
|
|
5
|
+
* const MyComponent = (props) => {
|
|
6
|
+
*
|
|
7
|
+
* const componentRef = useFocusTrap<HTMLDivElement>(props.isOpen);
|
|
8
|
+
*
|
|
9
|
+
* return props.isOpen ? <div><button>click</button></div> : null;
|
|
10
|
+
*
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
* @param active om focus skal fanges, f.eks. når en modal åpnes.
|
|
14
|
+
* @returns ref til elementet som fanger fokus.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useFocusTrap<T extends HTMLElement>(active: boolean): RefObject<T>;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Fanger fokus i en loop inni et element. Typisk bruk:
|
|
5
|
+
* ```
|
|
6
|
+
* const MyComponent = (props) => {
|
|
7
|
+
*
|
|
8
|
+
* const componentRef = useFocusTrap<HTMLDivElement>(props.isOpen);
|
|
9
|
+
*
|
|
10
|
+
* return props.isOpen ? <div><button>click</button></div> : null;
|
|
11
|
+
*
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
* @param active om focus skal fanges, f.eks. når en modal åpnes.
|
|
15
|
+
* @returns ref til elementet som fanger fokus.
|
|
16
|
+
*/
|
|
17
|
+
|
|
3
18
|
function useFocusTrap(active) {
|
|
4
19
|
var elementRef = useRef(null);
|
|
5
20
|
useEffect(function () {
|
|
@@ -1 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tillater effekter og animasjoner å bli gjennomført like etter et element blir lagt til eller like før det blir fjernet fra DOM.
|
|
3
|
+
* Typisk bruk:
|
|
4
|
+
* ```
|
|
5
|
+
* // CSS
|
|
6
|
+
* .component {
|
|
7
|
+
* transition: opacity 0.2s;
|
|
8
|
+
* opacity: 0;
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* .transitionedIn.mounted {
|
|
12
|
+
* opacity: 1;
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* const MyComponent = (props) => {
|
|
16
|
+
*
|
|
17
|
+
* const hasTransitionedIn = useMountTransition(props.isMounted, 500);
|
|
18
|
+
*
|
|
19
|
+
* return props.isMounted || hasTransitionedIn ? (
|
|
20
|
+
* <div
|
|
21
|
+
* className={`component ${hasTransitionedIn && 'transitionedIn'} ${props.isMounted && 'mounted'}`}
|
|
22
|
+
* >
|
|
23
|
+
* innhold
|
|
24
|
+
* </div>)
|
|
25
|
+
* : null;
|
|
26
|
+
*
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
* @param isMounted om elementet er mounted.
|
|
30
|
+
* @param unmountDelay hvor lenge transition skal vare før unmount.
|
|
31
|
+
* @returns om transition er ferdig.
|
|
32
|
+
*/
|
|
1
33
|
export declare const useMountTransition: (isMounted: boolean, unmountDelay: number) => boolean;
|
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Tillater effekter og animasjoner å bli gjennomført like etter et element blir lagt til eller like før det blir fjernet fra DOM.
|
|
6
|
+
* Typisk bruk:
|
|
7
|
+
* ```
|
|
8
|
+
* // CSS
|
|
9
|
+
* .component {
|
|
10
|
+
* transition: opacity 0.2s;
|
|
11
|
+
* opacity: 0;
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* .transitionedIn.mounted {
|
|
15
|
+
* opacity: 1;
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const MyComponent = (props) => {
|
|
19
|
+
*
|
|
20
|
+
* const hasTransitionedIn = useMountTransition(props.isMounted, 500);
|
|
21
|
+
*
|
|
22
|
+
* return props.isMounted || hasTransitionedIn ? (
|
|
23
|
+
* <div
|
|
24
|
+
* className={`component ${hasTransitionedIn && 'transitionedIn'} ${props.isMounted && 'mounted'}`}
|
|
25
|
+
* >
|
|
26
|
+
* innhold
|
|
27
|
+
* </div>)
|
|
28
|
+
* : null;
|
|
29
|
+
*
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
* @param isMounted om elementet er mounted.
|
|
33
|
+
* @param unmountDelay hvor lenge transition skal vare før unmount.
|
|
34
|
+
* @returns om transition er ferdig.
|
|
35
|
+
*/
|
|
36
|
+
|
|
4
37
|
var useMountTransition = function useMountTransition(isMounted, unmountDelay) {
|
|
5
38
|
var _useState = useState(false),
|
|
6
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -1 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kjører logikk når brukeren klikker utenfor et element, f.eks at elementet fjernes fra DOM.
|
|
3
|
+
* Typisk bruk:
|
|
4
|
+
* ```
|
|
5
|
+
* const [isOpen, setOpen] = useState(true);
|
|
6
|
+
* const ref = useRef<HTMLElement>(null);
|
|
7
|
+
* useOnClickOutside(ref, () => setOpen(false));
|
|
8
|
+
*
|
|
9
|
+
* return <div ref={ref}>innhold</div>
|
|
10
|
+
* ```
|
|
11
|
+
* @param element HTML elementet man klikker utenfor.
|
|
12
|
+
* @param handler funksjonen som kjøres ved klikk utenfor.
|
|
13
|
+
*/
|
|
1
14
|
export declare function useOnClickOutside(element: HTMLElement | null | (HTMLElement | null)[], handler: (event: MouseEvent | TouchEvent) => void): void;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Kjører logikk når brukeren klikker utenfor et element, f.eks at elementet fjernes fra DOM.
|
|
5
|
+
* Typisk bruk:
|
|
6
|
+
* ```
|
|
7
|
+
* const [isOpen, setOpen] = useState(true);
|
|
8
|
+
* const ref = useRef<HTMLElement>(null);
|
|
9
|
+
* useOnClickOutside(ref, () => setOpen(false));
|
|
10
|
+
*
|
|
11
|
+
* return <div ref={ref}>innhold</div>
|
|
12
|
+
* ```
|
|
13
|
+
* @param element HTML elementet man klikker utenfor.
|
|
14
|
+
* @param handler funksjonen som kjøres ved klikk utenfor.
|
|
15
|
+
*/
|
|
16
|
+
|
|
3
17
|
function useOnClickOutside(element, handler) {
|
|
4
18
|
useEffect(function () {
|
|
5
19
|
var listener = function listener(event) {
|
|
@@ -1 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kjører logikk når en spesifisert tast blir trykt ned.
|
|
3
|
+
* Typisk bruk:
|
|
4
|
+
* ```
|
|
5
|
+
* const [isOpen, setOpen] = useState(true);
|
|
6
|
+
* const ref = useRef<HTMLElement>(null);
|
|
7
|
+
* useOnKeyDown(['Escape', 'Esc'], () => setOpen(false));
|
|
8
|
+
*
|
|
9
|
+
* return isOpen ? <div>innhold</div> : null;
|
|
10
|
+
* ```
|
|
11
|
+
* @param key tasten som trykkes.
|
|
12
|
+
* @param handler funksjonen som skal kjøres.
|
|
13
|
+
*/
|
|
1
14
|
export declare const useOnKeyDown: (key: string | string[], handler: (event: KeyboardEvent) => void) => void;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Kjører logikk når en spesifisert tast blir trykt ned.
|
|
5
|
+
* Typisk bruk:
|
|
6
|
+
* ```
|
|
7
|
+
* const [isOpen, setOpen] = useState(true);
|
|
8
|
+
* const ref = useRef<HTMLElement>(null);
|
|
9
|
+
* useOnKeyDown(['Escape', 'Esc'], () => setOpen(false));
|
|
10
|
+
*
|
|
11
|
+
* return isOpen ? <div>innhold</div> : null;
|
|
12
|
+
* ```
|
|
13
|
+
* @param key tasten som trykkes.
|
|
14
|
+
* @param handler funksjonen som skal kjøres.
|
|
15
|
+
*/
|
|
16
|
+
|
|
3
17
|
var useOnKeyDown = function useOnKeyDown(key, handler) {
|
|
4
18
|
useEffect(function () {
|
|
5
19
|
var listener = function listener(event) {
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction, KeyboardEvent } from 'react';
|
|
2
2
|
import { Direction } from '../types';
|
|
3
3
|
export declare const isKeyboardEvent: (e: Event | KeyboardEvent<Element>) => e is KeyboardEvent<Element>;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Bytter fokus mellom elementer i en gruppe med piltaster og ikke Tab, og looper fokus i gruppen. Typisk bruk:
|
|
6
|
+
* ```
|
|
7
|
+
* import elements from './elements';
|
|
8
|
+
* import RoveItem from './RoveItem';
|
|
9
|
+
*
|
|
10
|
+
* const MyComponent = () => {
|
|
11
|
+
* const [focus, setFocus] = useRoveFocus(elements.length);
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <ul>
|
|
15
|
+
* {elements.map((element, index) => (
|
|
16
|
+
* <li key={element}>
|
|
17
|
+
* <RoveItem index={index} focus={focus === index} setFocus={setFocus}>{element.name}</RoveItem>
|
|
18
|
+
* </li>
|
|
19
|
+
* ))}
|
|
20
|
+
* </ul>)
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
* @param size antall elementer i gruppen.
|
|
24
|
+
* @param reset om fokus i gruppen skal nullstilles; når man tabber seg inn i gruppen skal focus være nullstilt.
|
|
25
|
+
* @param direction retning elementene blas i.
|
|
26
|
+
* @returns hook par: indeksen til fokuserte elemenentet og funksjonen som håndterer fokus.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useRoveFocus(size?: number, reset?: boolean, direction?: Direction): [number, Dispatch<SetStateAction<number>>];
|