@olenbetong/appframe-ds 1.7.1 → 1.8.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.
@@ -1,80 +1,101 @@
1
- /*
2
- * The wrapper is the visual input: it owns the border, background, hover and
3
- * focus styling, while the inner Designsystemet input is rendered bare so the
4
- * input and the adornments read as a single control.
5
- */
6
- .ObInputAdornments-root {
7
- --obInputAdornments-padding: 0.25rem;
8
- --obInputAdornments-gap: 0.25rem;
9
- --obInputAdornments-fontSize: var(--ds-font-size-3, 1rem);
10
-
11
- display: flex;
12
- align-items: center;
13
- box-sizing: border-box;
14
- gap: var(--obInputAdornments-gap);
15
- padding: var(--obInputAdornments-padding);
16
- inline-size: 100%;
17
- color: var(--ds-color-neutral-text-default, #1e2b3c);
18
- background-color: var(--ds-color-neutral-surface-default, #fff);
19
- border: var(--ds-border-width-default, 1px) solid var(--ds-color-neutral-border-default, #b3b3b3);
20
- border-radius: var(--ds-border-radius-md, 0.375rem);
21
- }
22
-
23
- /* Designsystemet components come in sm, md and lg; xs and xl are typography-only sizes */
24
- .ObInputAdornments-root[data-size="sm"] {
25
- --obInputAdornments-padding: 0.25rem;
26
- --obInputAdornments-fontSize: var(--ds-font-size-2, 0.875rem);
27
- }
28
-
29
- .ObInputAdornments-root[data-size="md"] {
30
- --obInputAdornments-padding: 0.25rem;
31
- --obInputAdornments-fontSize: var(--ds-font-size-3, 1rem);
32
- }
33
-
34
- .ObInputAdornments-root[data-size="lg"] {
35
- --obInputAdornments-padding: 0.375rem;
36
- --obInputAdornments-fontSize: var(--ds-font-size-4, 1.125rem);
37
- }
38
-
39
- /* The Designsystemet input hover (an inner outline doubling the border), drawn on the wrapper */
40
- .ObInputAdornments-root:hover:not(
41
- :focus-within,
42
- :has(.ObInputAdornments-field:disabled, .ObInputAdornments-field[readonly])
43
- ) {
44
- outline: var(--ds-border-width-default, 1px) solid var(--ds-color-neutral-border-default, #b3b3b3);
45
- outline-offset: -0.1px;
46
- }
47
-
48
- .ObInputAdornments-root:has(.ObInputAdornments-field:focus-visible) {
49
- box-shadow: var(--dsc-focus-boxShadow);
50
- outline: var(--dsc-focus-outline);
51
- outline-offset: var(--ds-border-width-focus, 3px);
52
- }
53
-
54
- .ObInputAdornments-root:has(.ObInputAdornments-field:disabled) {
55
- cursor: not-allowed;
56
- opacity: var(--ds-disabled-opacity, 0.3);
57
- }
58
-
59
- /* The bare input: all the visual styling lives on the wrapper instead */
60
- .ObInputAdornments-root .ObInputAdornments-field {
61
- flex: 1;
62
- min-inline-size: 0;
63
- font-size: var(--obInputAdornments-fontSize);
64
- background: transparent;
65
- border: none;
66
- }
67
-
68
- .ObInputAdornments-root .ObInputAdornments-field:disabled {
69
- opacity: 1;
70
- }
71
-
72
- .ObInputAdornments-root .ObInputAdornments-field:hover {
73
- outline: none;
74
- }
75
-
76
- .ObInputAdornments-root .ObInputAdornments-field:focus-visible {
77
- box-shadow: none;
78
- outline: none;
79
- outline-offset: 0;
80
- }
1
+ /*
2
+ * The wrapper is the visual input: it owns the border, background, hover and
3
+ * focus styling, while the inner Designsystemet input is rendered bare so the
4
+ * input and the adornments read as a single control.
5
+ */
6
+ .ObInputAdornments-root {
7
+ --obInputAdornments-padding: 0.25rem;
8
+ --obInputAdornments-gap: 0.25rem;
9
+ /* A Textfield's font size (`--dsc-input-font-size`) when no `data-size` is given. */
10
+ --obInputAdornments-fontSize: max(1rem, 1em);
11
+
12
+ display: flex;
13
+ align-items: center;
14
+ box-sizing: border-box;
15
+ gap: var(--obInputAdornments-gap);
16
+ padding: var(--obInputAdornments-padding);
17
+ inline-size: 100%;
18
+ color: var(--ds-color-neutral-text-default, #1e2b3c);
19
+ background-color: var(--ds-color-neutral-surface-default, #fff);
20
+ border: var(--ds-border-width-default, 1px) solid var(--ds-color-neutral-border-default, #b3b3b3);
21
+ border-radius: var(--ds-border-radius-md, 0.375rem);
22
+
23
+ /*
24
+ * As tall as a Textfield (`--dsc-input-size`), whatever the adornments are: the bare input and
25
+ * any button inside get the height left inside the padding and border, so a full-size
26
+ * Designsystemet button no longer makes the control taller than the fields beside it.
27
+ */
28
+ --obInputAdornments-innerSize: calc(
29
+ var(--ds-size-12) - 2 * var(--obInputAdornments-padding) - 2 * var(--ds-border-width-default, 1px)
30
+ );
31
+
32
+ min-block-size: var(--ds-size-12);
33
+ }
34
+
35
+ .ObInputAdornments-root > .ds-button {
36
+ --dsc-button-size: var(--obInputAdornments-innerSize);
37
+ --dsc-button-padding: 0 var(--ds-size-2);
38
+ }
39
+
40
+ /* Designsystemet components come in sm, md and lg; xs and xl are typography-only sizes */
41
+ .ObInputAdornments-root[data-size="sm"] {
42
+ --obInputAdornments-padding: 0.25rem;
43
+ --obInputAdornments-fontSize: var(--ds-font-size-2, 0.875rem);
44
+ }
45
+
46
+ .ObInputAdornments-root[data-size="md"] {
47
+ --obInputAdornments-padding: 0.25rem;
48
+ --obInputAdornments-fontSize: var(--ds-font-size-3, 1rem);
49
+ }
50
+
51
+ .ObInputAdornments-root[data-size="lg"] {
52
+ --obInputAdornments-padding: 0.375rem;
53
+ --obInputAdornments-fontSize: var(--ds-font-size-4, 1.125rem);
54
+ }
55
+
56
+ /* The Designsystemet input hover (an inner outline doubling the border), drawn on the wrapper */
57
+ .ObInputAdornments-root:hover:not(
58
+ :focus-within,
59
+ :has(.ObInputAdornments-field:disabled, .ObInputAdornments-field[readonly])
60
+ ) {
61
+ outline: var(--ds-border-width-default, 1px) solid var(--ds-color-neutral-border-default, #b3b3b3);
62
+ outline-offset: -0.1px;
63
+ }
64
+
65
+ .ObInputAdornments-root:has(.ObInputAdornments-field:focus-visible) {
66
+ box-shadow: var(--dsc-focus-boxShadow);
67
+ outline: var(--dsc-focus-outline);
68
+ outline-offset: var(--ds-border-width-focus, 3px);
69
+ }
70
+
71
+ .ObInputAdornments-root:has(.ObInputAdornments-field:disabled) {
72
+ cursor: not-allowed;
73
+ opacity: var(--ds-disabled-opacity, 0.3);
74
+ }
75
+
76
+ /* The bare input: all the visual styling lives on the wrapper instead */
77
+ .ObInputAdornments-root .ObInputAdornments-field {
78
+ --dsc-input-size: var(--obInputAdornments-innerSize);
79
+ /* The text starts where a Textfield's does (its inline padding, inside the wrapper's own). */
80
+ --dsc-input-padding-inline: calc(var(--ds-size-3) - var(--obInputAdornments-padding));
81
+
82
+ flex: 1;
83
+ min-inline-size: 0;
84
+ font-size: var(--obInputAdornments-fontSize);
85
+ background: transparent;
86
+ border: none;
87
+ }
88
+
89
+ .ObInputAdornments-root .ObInputAdornments-field:disabled {
90
+ opacity: 1;
91
+ }
92
+
93
+ .ObInputAdornments-root .ObInputAdornments-field:hover {
94
+ outline: none;
95
+ }
96
+
97
+ .ObInputAdornments-root .ObInputAdornments-field:focus-visible {
98
+ box-shadow: none;
99
+ outline: none;
100
+ outline-offset: 0;
101
+ }
@@ -1,102 +1,102 @@
1
- import "./InputAdornments.css";
2
-
3
- import { Input, type InputProps } from "@digdir/designsystemet-react";
4
- import clsx from "clsx";
5
- import { Children, isValidElement, type ReactElement, type ReactNode, type Ref } from "react";
6
-
7
- export type InputSlotProps = {
8
- /**
9
- * Extra classes for the input rendered in this slot
10
- */
11
- className?: string;
12
- };
13
-
14
- /**
15
- * Marks where the input should be rendered among the children of
16
- * `InputAdornments`. Renders nothing on its own; `InputAdornments` swaps it
17
- * for the actual input. When it is left out, the input is rendered before the
18
- * adornments.
19
- *
20
- * @example
21
- * ```jsx
22
- * <InputAdornments value={value} onChange={handleChange}>
23
- * <SearchIcon aria-hidden />
24
- * <InputSlot />
25
- * <Button icon variant="tertiary"><XMarkIcon aria-hidden /></Button>
26
- * </InputAdornments>
27
- * ```
28
- */
29
- export function InputSlot(_props: InputSlotProps) {
30
- return null;
31
- }
32
-
33
- export type InputAdornmentsProps = Omit<InputProps, "children"> & {
34
- /**
35
- * Adornments rendered next to the input, e.g. icons or buttons. Include an
36
- * `InputSlot` to control where the input itself ends up.
37
- */
38
- children?: ReactNode;
39
- /**
40
- * Classes for the wrapper that carries the input styling
41
- */
42
- className?: string;
43
- /**
44
- * Classes for the bare input element itself
45
- */
46
- inputClassName?: string;
47
- /**
48
- * Ref to the input element. The wrapper is an implementation detail, so the
49
- * ref points at the input rather than at the element carrying the styling.
50
- */
51
- ref?: Ref<HTMLInputElement>;
52
- };
53
-
54
- /**
55
- * Input with adornments, equivalent to a MUI `TextField` with
56
- * `InputProps.startAdornment` / `endAdornment`. Designsystemet has no
57
- * equivalent, so the border, background, hover and focus styling is moved from
58
- * the input onto a wrapper element, making the input and its adornments read
59
- * as a single control.
60
- *
61
- * All other props are forwarded to the Designsystemet `Input`, so `ref`,
62
- * `value`, `onChange`, `data-size` and `data-color` work as usual.
63
- *
64
- * @example
65
- * ```jsx
66
- * // Input first (default), adornments after
67
- * <InputAdornments aria-label="Search" value={value} onChange={handleChange}>
68
- * <Button icon variant="tertiary"><MagnifyingGlassIcon aria-hidden /></Button>
69
- * </InputAdornments>
70
- *
71
- * // Explicit placement with InputSlot
72
- * <InputAdornments aria-label="Amount" data-size="lg">
73
- * <span aria-hidden>kr</span>
74
- * <InputSlot />
75
- * <span aria-hidden>,-</span>
76
- * </InputAdornments>
77
- * ```
78
- */
79
- export function InputAdornments({ children, className, inputClassName, ...props }: InputAdornmentsProps) {
80
- let size = props["data-size"];
81
- let color = props["data-color"];
82
- let childArray = Children.toArray(children);
83
- let slot = childArray.find((child) => isValidElement(child) && child.type === InputSlot) as
84
- | ReactElement<InputSlotProps>
85
- | undefined;
86
-
87
- let input = (
88
- <Input
89
- key="ObInputAdornments-input"
90
- {...props}
91
- className={clsx("ObInputAdornments-field", inputClassName, slot?.props.className)}
92
- />
93
- );
94
-
95
- let content = slot ? childArray.map((child) => (child === slot ? input : child)) : [input, ...childArray];
96
-
97
- return (
98
- <div className={clsx("ObInputAdornments-root", className)} data-size={size} data-color={color}>
99
- {content}
100
- </div>
101
- );
102
- }
1
+ import "./InputAdornments.css";
2
+
3
+ import { Input, type InputProps } from "@digdir/designsystemet-react";
4
+ import clsx from "clsx";
5
+ import { Children, isValidElement, type ReactElement, type ReactNode, type Ref } from "react";
6
+
7
+ export type InputSlotProps = {
8
+ /**
9
+ * Extra classes for the input rendered in this slot
10
+ */
11
+ className?: string;
12
+ };
13
+
14
+ /**
15
+ * Marks where the input should be rendered among the children of
16
+ * `InputAdornments`. Renders nothing on its own; `InputAdornments` swaps it
17
+ * for the actual input. When it is left out, the input is rendered before the
18
+ * adornments.
19
+ *
20
+ * @example
21
+ * ```jsx
22
+ * <InputAdornments value={value} onChange={handleChange}>
23
+ * <SearchIcon aria-hidden />
24
+ * <InputSlot />
25
+ * <Button icon variant="tertiary"><XMarkIcon aria-hidden /></Button>
26
+ * </InputAdornments>
27
+ * ```
28
+ */
29
+ export function InputSlot(_props: InputSlotProps) {
30
+ return null;
31
+ }
32
+
33
+ export type InputAdornmentsProps = Omit<InputProps, "children"> & {
34
+ /**
35
+ * Adornments rendered next to the input, e.g. icons or buttons. Include an
36
+ * `InputSlot` to control where the input itself ends up.
37
+ */
38
+ children?: ReactNode;
39
+ /**
40
+ * Classes for the wrapper that carries the input styling
41
+ */
42
+ className?: string;
43
+ /**
44
+ * Classes for the bare input element itself
45
+ */
46
+ inputClassName?: string;
47
+ /**
48
+ * Ref to the input element. The wrapper is an implementation detail, so the
49
+ * ref points at the input rather than at the element carrying the styling.
50
+ */
51
+ ref?: Ref<HTMLInputElement>;
52
+ };
53
+
54
+ /**
55
+ * Input with adornments, equivalent to a MUI `TextField` with
56
+ * `InputProps.startAdornment` / `endAdornment`. Designsystemet has no
57
+ * equivalent, so the border, background, hover and focus styling is moved from
58
+ * the input onto a wrapper element, making the input and its adornments read
59
+ * as a single control.
60
+ *
61
+ * All other props are forwarded to the Designsystemet `Input`, so `ref`,
62
+ * `value`, `onChange`, `data-size` and `data-color` work as usual.
63
+ *
64
+ * @example
65
+ * ```jsx
66
+ * // Input first (default), adornments after
67
+ * <InputAdornments aria-label="Search" value={value} onChange={handleChange}>
68
+ * <Button icon variant="tertiary"><MagnifyingGlassIcon aria-hidden /></Button>
69
+ * </InputAdornments>
70
+ *
71
+ * // Explicit placement with InputSlot
72
+ * <InputAdornments aria-label="Amount" data-size="lg">
73
+ * <span aria-hidden>kr</span>
74
+ * <InputSlot />
75
+ * <span aria-hidden>,-</span>
76
+ * </InputAdornments>
77
+ * ```
78
+ */
79
+ export function InputAdornments({ children, className, inputClassName, ...props }: InputAdornmentsProps) {
80
+ let size = props["data-size"];
81
+ let color = props["data-color"];
82
+ let childArray = Children.toArray(children);
83
+ let slot = childArray.find((child) => isValidElement(child) && child.type === InputSlot) as
84
+ | ReactElement<InputSlotProps>
85
+ | undefined;
86
+
87
+ let input = (
88
+ <Input
89
+ key="ObInputAdornments-input"
90
+ {...props}
91
+ className={clsx("ObInputAdornments-field", inputClassName, slot?.props.className)}
92
+ />
93
+ );
94
+
95
+ let content = slot ? childArray.map((child) => (child === slot ? input : child)) : [input, ...childArray];
96
+
97
+ return (
98
+ <div className={clsx("ObInputAdornments-root", className)} data-size={size} data-color={color}>
99
+ {content}
100
+ </div>
101
+ );
102
+ }
@@ -1,9 +1,9 @@
1
- .ObNumberInput-root .ObInputAdornments-field {
2
- /* Numbers read best right aligned, and the steppers sit at the end anyway */
3
- text-align: end;
4
- font-variant-numeric: tabular-nums;
5
- }
6
-
7
- .ObNumberInput-root .ObNumberInput-stepper {
8
- flex-shrink: 0;
9
- }
1
+ .ObNumberInput-root .ObInputAdornments-field {
2
+ /* Numbers read best right aligned, and the steppers sit at the end anyway */
3
+ text-align: end;
4
+ font-variant-numeric: tabular-nums;
5
+ }
6
+
7
+ .ObNumberInput-root .ObNumberInput-stepper {
8
+ flex-shrink: 0;
9
+ }