@kystverket/styrbord 2.15.1 → 2.16.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/src/components/kystverket/ColorSchemeToggle/ColorSchemeToggle.d.ts +15 -0
- package/dist/src/components/kystverket/ColorSchemeToggle/ColorSchemeToggle.stories.d.ts +41 -0
- package/dist/src/components/kystverket/ColorSchemeToggle/ColorSchemeToggle.types.d.ts +16 -0
- package/dist/src/components/kystverket/ColorSchemeToggle/useColorScheme.d.ts +21 -0
- package/dist/src/components/kystverket/KyvSpinner/KyvSpinner.d.ts +8 -1
- package/dist/src/components/kystverket/KyvSpinner/KyvSpinner.stories.d.ts +8 -1
- package/dist/src/main.d.ts +3 -0
- package/dist/style.css +1 -1
- package/dist/style.js +2921 -2627
- package/dist/style.umd.cjs +12 -12
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { ColorSchemeToggleProps } from './ColorSchemeToggle.types';
|
|
3
|
+
/**
|
|
4
|
+
* Round 48 px button that switches between light and dark colour scheme. Shows a sun over the sea in
|
|
5
|
+
* light mode; in dark mode the sun sinks and a crescent moon and stars appear.
|
|
6
|
+
*
|
|
7
|
+
* Controlled: pair it with `useColorScheme`, which stores the choice and sets `data-color-scheme`
|
|
8
|
+
* on `<html>`. The accessible name describes the action ("Bytt til mørk modus") and changes with
|
|
9
|
+
* the state, so the button has no `aria-pressed`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const [colorScheme, setColorScheme] = useColorScheme();
|
|
13
|
+
* <ColorSchemeToggle colorScheme={colorScheme} onColorSchemeChange={setColorScheme} />
|
|
14
|
+
*/
|
|
15
|
+
export declare function ColorSchemeToggle({ colorScheme, onColorSchemeChange, variant, className, style, onClick, ...rest }: ColorSchemeToggleProps): ReactElement;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { ColorSchemeToggle } from '~/main';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof ColorSchemeToggle;
|
|
6
|
+
tags: string[];
|
|
7
|
+
args: {
|
|
8
|
+
colorScheme: "light";
|
|
9
|
+
onColorSchemeChange: () => void;
|
|
10
|
+
variant: "color";
|
|
11
|
+
};
|
|
12
|
+
argTypes: {
|
|
13
|
+
colorScheme: {
|
|
14
|
+
control: false;
|
|
15
|
+
};
|
|
16
|
+
onColorSchemeChange: {
|
|
17
|
+
control: false;
|
|
18
|
+
};
|
|
19
|
+
variant: {
|
|
20
|
+
control: "inline-radio";
|
|
21
|
+
options: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
parameters: {
|
|
25
|
+
docs: {
|
|
26
|
+
description: {
|
|
27
|
+
component: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default meta;
|
|
33
|
+
type Story = StoryObj<typeof meta>;
|
|
34
|
+
export declare const Preview: Story;
|
|
35
|
+
export declare const Variants: Story;
|
|
36
|
+
export declare const AllStates: Story;
|
|
37
|
+
/**
|
|
38
|
+
* With `useColorScheme` the page follows the system until the user picks the other scheme. That choice
|
|
39
|
+
* survives a reload; picking what the system shows clears it and the page follows the system again.
|
|
40
|
+
*/
|
|
41
|
+
export declare const WithHook: Story;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, Ref } from 'react';
|
|
2
|
+
export type ColorScheme = 'light' | 'dark';
|
|
3
|
+
export type ColorSchemeToggleVariant = 'color' | 'mono';
|
|
4
|
+
export type ColorSchemeToggleProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'children' | 'onChange' | 'aria-label' | 'title'> & {
|
|
5
|
+
/** The colour scheme currently in use. The button shows a sun for `light` and a moon for `dark`. */
|
|
6
|
+
colorScheme: ColorScheme;
|
|
7
|
+
/** Called with the opposite scheme when the button is clicked. Not called if `onClick` prevents default. */
|
|
8
|
+
onColorSchemeChange: (next: ColorScheme) => void;
|
|
9
|
+
/**
|
|
10
|
+
* `color` draws sky, sea and a yellow sun. `mono` is a single-colour line icon in
|
|
11
|
+
* `primary-base-default` on `primary-surface-default`, and follows the page's colour scheme.
|
|
12
|
+
* @default 'color'
|
|
13
|
+
*/
|
|
14
|
+
variant?: ColorSchemeToggleVariant;
|
|
15
|
+
ref?: Ref<HTMLButtonElement>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ColorScheme } from './ColorSchemeToggle.types';
|
|
2
|
+
export declare const COLOR_SCHEME_STORAGE_KEY = "styrbord-color-scheme";
|
|
3
|
+
/**
|
|
4
|
+
* Owns the page's colour scheme. By default the page follows the system setting
|
|
5
|
+
* (`prefers-color-scheme`): `<html>` gets `data-color-scheme="auto"` and the tokens switch in CSS, live.
|
|
6
|
+
* A choice that differs from the system is saved in `localStorage` under `styrbord-color-scheme` and
|
|
7
|
+
* set as `data-color-scheme="light|dark"`; choosing what the system shows clears it again.
|
|
8
|
+
* All components using the hook share one value.
|
|
9
|
+
*
|
|
10
|
+
* Returns the scheme in use (resolved from the system when following it), a setter, and whether the
|
|
11
|
+
* page is following the system.
|
|
12
|
+
*
|
|
13
|
+
* During server rendering and hydration the scheme is `light`. Render `<html data-color-scheme="auto">`
|
|
14
|
+
* so system users get the right scheme before JavaScript runs. Users with a stored choice need an
|
|
15
|
+
* inline script in `<head>` that applies it before first paint.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const [colorScheme, setColorScheme] = useColorScheme();
|
|
19
|
+
* <ColorSchemeToggle colorScheme={colorScheme} onColorSchemeChange={setColorScheme} />
|
|
20
|
+
*/
|
|
21
|
+
export declare function useColorScheme(): readonly [ColorScheme, (next: ColorScheme) => void, boolean];
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
1
2
|
type KyvSpinnerSize = 'sm' | 'md' | 'lg';
|
|
3
|
+
type KyvSpinnerVariant = 'scene' | 'outline';
|
|
2
4
|
export interface KyvSpinnerProps {
|
|
3
5
|
size?: KyvSpinnerSize;
|
|
6
|
+
/**
|
|
7
|
+
* `outline` (standard) er en strektegning på gjennomsiktig bakgrunn, i samme stil som fyr-ikonet.
|
|
8
|
+
* `scene` er en fargelagt scene med himmel, hav og øy, som skifter mellom dag og natt.
|
|
9
|
+
*/
|
|
10
|
+
variant?: KyvSpinnerVariant;
|
|
4
11
|
'aria-label'?: string;
|
|
5
12
|
className?: string;
|
|
6
13
|
}
|
|
7
|
-
declare const KyvSpinner: ({ size, "aria-label": ariaLabel, className }: KyvSpinnerProps) =>
|
|
14
|
+
declare const KyvSpinner: ({ size, variant, "aria-label": ariaLabel, className, }: KyvSpinnerProps) => ReactElement;
|
|
8
15
|
export default KyvSpinner;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StoryObj } from '@storybook/react-vite';
|
|
2
2
|
declare const meta: {
|
|
3
3
|
title: string;
|
|
4
|
-
component: ({ size, "aria-label": ariaLabel, className }: import("./KyvSpinner").KyvSpinnerProps) => React.
|
|
4
|
+
component: ({ size, variant, "aria-label": ariaLabel, className, }: import("./KyvSpinner").KyvSpinnerProps) => React.ReactElement;
|
|
5
5
|
decorators: ((Story: import("storybook/internal/csf").PartialStoryFn, context: import("storybook/internal/csf").StoryContext) => React.JSX.Element)[];
|
|
6
6
|
tags: string[];
|
|
7
7
|
parameters: {
|
|
@@ -16,6 +16,10 @@ declare const meta: {
|
|
|
16
16
|
control: "radio";
|
|
17
17
|
options: string[];
|
|
18
18
|
};
|
|
19
|
+
variant: {
|
|
20
|
+
control: "radio";
|
|
21
|
+
options: string[];
|
|
22
|
+
};
|
|
19
23
|
};
|
|
20
24
|
};
|
|
21
25
|
export default meta;
|
|
@@ -24,3 +28,6 @@ export declare const Default: Story;
|
|
|
24
28
|
export declare const Small: Story;
|
|
25
29
|
export declare const Large: Story;
|
|
26
30
|
export declare const AllSizes: Story;
|
|
31
|
+
export declare const DayAndNight: Story;
|
|
32
|
+
export declare const Scene: Story;
|
|
33
|
+
export declare const SceneDayAndNight: Story;
|
package/dist/src/main.d.ts
CHANGED
|
@@ -48,6 +48,9 @@ export { Logo } from './components/kystverket/Logo/Logo';
|
|
|
48
48
|
export type { LogoProps, LogoVariant } from './components/kystverket/Logo/Logo';
|
|
49
49
|
export { Search, SearchInput, SearchClear, SearchButton } from './components/kystverket/Search/Search';
|
|
50
50
|
export type { SearchProps, SearchInputProps, SearchClearProps, SearchButtonProps, } from './components/kystverket/Search/Search.types';
|
|
51
|
+
export { ColorSchemeToggle } from './components/kystverket/ColorSchemeToggle/ColorSchemeToggle';
|
|
52
|
+
export type { ColorScheme, ColorSchemeToggleProps, ColorSchemeToggleVariant, } from './components/kystverket/ColorSchemeToggle/ColorSchemeToggle.types';
|
|
53
|
+
export { useColorScheme, COLOR_SCHEME_STORAGE_KEY } from './components/kystverket/ColorSchemeToggle/useColorScheme';
|
|
51
54
|
export { Footer } from './components/kystverket/Footer/Footer';
|
|
52
55
|
export type { FooterProps } from './components/kystverket/Footer/Footer';
|
|
53
56
|
export { Header } from './components/kystverket/Header/Header';
|