@ks-digital/designsystem-angular 0.0.1-alpha.23 → 0.0.1-alpha.25
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/.storybook/customTheme.ts +15 -0
- package/.storybook/default-args.ts +18 -0
- package/.storybook/main.ts +27 -0
- package/.storybook/manager.ts +10 -0
- package/.storybook/preview-head.html +16 -0
- package/.storybook/preview.ts +70 -0
- package/.storybook/themes.ts +9 -0
- package/.storybook/tsconfig.json +16 -0
- package/.storybook/vite.config.mts +5 -0
- package/README.md +3 -3
- package/eslint.config.mjs +28 -0
- package/ng-package.json +9 -0
- package/package.json +18 -27
- package/project.json +81 -0
- package/src/components/alert/alert.mdx +46 -0
- package/src/components/alert/alert.spec.ts +33 -0
- package/src/components/alert/alert.stories.ts +138 -0
- package/src/components/alert/alert.ts +46 -0
- package/src/components/alert/index.ts +1 -0
- package/src/components/button/button.mdx +40 -0
- package/src/components/button/button.spec.ts +86 -0
- package/src/components/button/button.stories.ts +123 -0
- package/src/components/button/button.ts +60 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/card/card-block.ts +10 -0
- package/src/components/card/card.mdx +100 -0
- package/src/components/card/card.spec.ts +70 -0
- package/src/components/card/card.stories.ts +101 -0
- package/src/components/card/card.ts +44 -0
- package/src/components/card/index.ts +2 -0
- package/src/components/checkbox/README.md +13 -0
- package/src/components/checkbox/checkbox.mdx +50 -0
- package/src/components/checkbox/checkbox.spec.ts +21 -0
- package/src/components/checkbox/checkbox.stories.ts +182 -0
- package/src/components/checkbox/index.ts +0 -0
- package/src/components/colors.ts +36 -0
- package/src/components/common-inputs.ts +30 -0
- package/src/components/details/controlled-details.ts +63 -0
- package/src/components/details/details-content.ts +7 -0
- package/src/components/details/details-summary.ts +7 -0
- package/src/components/details/details.mdx +89 -0
- package/src/components/details/details.spec.ts +56 -0
- package/src/components/details/details.stories.ts +129 -0
- package/src/components/details/details.ts +69 -0
- package/src/components/details/index.ts +3 -0
- package/src/components/field/field-counter.ts +56 -0
- package/src/components/field/field-description.ts +10 -0
- package/src/components/field/field-error.ts +13 -0
- package/src/components/field/field-observer.ts +121 -0
- package/src/components/field/field-state.ts +21 -0
- package/src/components/field/field.mdx +40 -0
- package/src/components/field/field.spec.ts +131 -0
- package/src/components/field/field.stories.ts +98 -0
- package/src/components/field/field.ts +70 -0
- package/src/components/field/index.ts +3 -0
- package/src/components/fieldset/fieldset-description.ts +8 -0
- package/src/components/fieldset/fieldset-legend.ts +11 -0
- package/src/components/fieldset/fieldset.spec.ts +80 -0
- package/src/components/fieldset/fieldset.ts +11 -0
- package/src/components/fieldset/index.ts +3 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.mdx +11 -0
- package/src/components/input/input.spec.ts +25 -0
- package/src/components/input/input.stories.ts +72 -0
- package/src/components/input/input.ts +67 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/label/label.ts +17 -0
- package/src/components/paragraph/index.ts +1 -0
- package/src/components/paragraph/paragraph.ts +10 -0
- package/src/components/popover/controlled-popover.ts +62 -0
- package/src/components/popover/index.ts +1 -0
- package/src/components/popover/popover.mdx +81 -0
- package/src/components/popover/popover.spec.ts +143 -0
- package/src/components/popover/popover.stories.ts +63 -0
- package/src/components/popover/popover.ts +186 -0
- package/src/components/radio/radio.mdx +117 -0
- package/src/components/radio/radio.stories.ts +226 -0
- package/src/components/search/index.ts +4 -0
- package/src/components/search/search-button.ts +35 -0
- package/src/components/search/search-clear.ts +57 -0
- package/src/components/search/search-input.ts +18 -0
- package/src/components/search/search.mdx +56 -0
- package/src/components/search/search.spec.ts +48 -0
- package/src/components/search/search.stories.ts +205 -0
- package/src/components/search/search.ts +50 -0
- package/src/components/spinner/index.ts +1 -0
- package/src/components/spinner/spinner.mdx +24 -0
- package/src/components/spinner/spinner.spec.ts +13 -0
- package/src/components/spinner/spinner.stories.ts +54 -0
- package/src/components/spinner/spinner.ts +62 -0
- package/src/components/switch/switch.mdx +82 -0
- package/src/components/switch/switch.stories.ts +94 -0
- package/src/components/textarea/textarea.mdx +14 -0
- package/src/components/textarea/textarea.stories.ts +52 -0
- package/src/components/validation-message/index.ts +1 -0
- package/src/components/validation-message/validation-message.ts +11 -0
- package/src/index.ts +14 -0
- package/src/test-setup.ts +12 -0
- package/src/utils/log-if-devmode.ts +13 -0
- package/src/utils/random-id.ts +3 -0
- package/tsconfig.json +34 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +30 -0
- package/vite.config.mts +35 -0
- package/dist/README.md +0 -55
- package/dist/fesm2022/ks-digital-designsystem-angular.mjs +0 -1068
- package/dist/fesm2022/ks-digital-designsystem-angular.mjs.map +0 -1
- package/dist/index.d.ts +0 -315
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { create } from 'storybook/theming'
|
|
2
|
+
|
|
3
|
+
export default create({
|
|
4
|
+
brandTitle: 'Komponenter',
|
|
5
|
+
fontBase: '"Inter", sans-serif',
|
|
6
|
+
// Colors
|
|
7
|
+
base: 'light',
|
|
8
|
+
colorSecondary: '#0062BA',
|
|
9
|
+
barTextColor: '#243142',
|
|
10
|
+
textColor: '#1e2b3c', // TODO does not work with css vars atm. bug?
|
|
11
|
+
inputTextColor: '#243142',
|
|
12
|
+
appBg: '#fefefe',
|
|
13
|
+
appPreviewBg: 'var(--ds-color-neutral-background-default)',
|
|
14
|
+
appContentBg: '#fefefe',
|
|
15
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Color } from '../src/components/colors'
|
|
2
|
+
import { Size } from '../src/components/common-inputs'
|
|
3
|
+
|
|
4
|
+
export type CommonArgs = {
|
|
5
|
+
'data-size'?: Size | undefined
|
|
6
|
+
'data-color'?: Color | undefined
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const commonArgTypes = {
|
|
10
|
+
'data-size': {
|
|
11
|
+
options: ['sm', 'md', 'lg'],
|
|
12
|
+
control: { type: 'radio' },
|
|
13
|
+
},
|
|
14
|
+
'data-color': {
|
|
15
|
+
options: ['accent', 'neutral', 'danger', 'info', 'success', 'warning'],
|
|
16
|
+
control: { type: 'radio' },
|
|
17
|
+
},
|
|
18
|
+
} satisfies import('@storybook/angular').ArgTypes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StorybookConfig } from '@analogjs/storybook-angular'
|
|
2
|
+
|
|
3
|
+
const config: StorybookConfig = {
|
|
4
|
+
stories: ['../**/*.@(mdx|stories.@(js|jsx|ts|tsx))'],
|
|
5
|
+
addons: ['@storybook/addon-docs'],
|
|
6
|
+
core: {
|
|
7
|
+
disableTelemetry: true,
|
|
8
|
+
},
|
|
9
|
+
framework: {
|
|
10
|
+
name: '@analogjs/storybook-angular',
|
|
11
|
+
options: {
|
|
12
|
+
builder: {
|
|
13
|
+
viteConfigPath: 'packages/angular/.storybook/vite.config.mts',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
staticDirs: [
|
|
18
|
+
// Map the local themes directory to a public path
|
|
19
|
+
{ from: '../../themes/dist', to: '/css' },
|
|
20
|
+
],
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default config
|
|
24
|
+
|
|
25
|
+
// To customize your Vite configuration you can use the viteFinal field.
|
|
26
|
+
// Check https://storybook.js.org/docs/react/builders/vite#configuration
|
|
27
|
+
// and https://nx.dev/recipes/storybook/custom-builder-configs
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<link
|
|
2
|
+
href="https://static.fiks.ks.no/googlefonts/googleapis/css2?family=Inter:wght@400;500;600;700;800&display=swap"
|
|
3
|
+
rel="stylesheet"
|
|
4
|
+
/>
|
|
5
|
+
|
|
6
|
+
<link rel="stylesheet" href="css/base.css" />
|
|
7
|
+
|
|
8
|
+
<style>
|
|
9
|
+
* {
|
|
10
|
+
font-feature-settings: 'cv05' 1;
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
document.documentElement.setAttribute('lang', 'no')
|
|
16
|
+
</script>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { applicationConfig, type Preview } from '@analogjs/storybook-angular'
|
|
2
|
+
import { provideZonelessChangeDetection } from '@angular/core'
|
|
3
|
+
import { addons } from 'storybook/preview-api'
|
|
4
|
+
import customTheme from './customTheme'
|
|
5
|
+
import { themes } from './themes'
|
|
6
|
+
|
|
7
|
+
addons.getChannel().on('globalsUpdated', ({ globals }) => {
|
|
8
|
+
setTheme(globals.theme)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function setTheme(href: string): void {
|
|
12
|
+
let link: HTMLLinkElement | null = document.getElementById(
|
|
13
|
+
'storybook-theme',
|
|
14
|
+
) as HTMLLinkElement | null
|
|
15
|
+
href = href ?? themes[0].href
|
|
16
|
+
if (!link) {
|
|
17
|
+
link = document.createElement('link')
|
|
18
|
+
link.rel = 'stylesheet'
|
|
19
|
+
link.id = 'storybook-theme'
|
|
20
|
+
document.head.appendChild(link)
|
|
21
|
+
}
|
|
22
|
+
link.href = href
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ThemeGlobalType = {
|
|
26
|
+
name: string
|
|
27
|
+
description: string
|
|
28
|
+
defaultValue: string
|
|
29
|
+
toolbar: {
|
|
30
|
+
icon: string
|
|
31
|
+
items: Array<{ value: string; title: string }>
|
|
32
|
+
showName: boolean
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const globalTypes: Record<string, ThemeGlobalType> = {
|
|
37
|
+
theme: {
|
|
38
|
+
name: 'Theme',
|
|
39
|
+
description: 'Global theme for components',
|
|
40
|
+
defaultValue: themes[0].href,
|
|
41
|
+
toolbar: {
|
|
42
|
+
icon: 'paintbrush',
|
|
43
|
+
items: themes.map((t) => ({ value: t.href, title: t.name })),
|
|
44
|
+
showName: true,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const preview: Preview = {
|
|
50
|
+
decorators: [
|
|
51
|
+
applicationConfig({
|
|
52
|
+
providers: [provideZonelessChangeDetection()],
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
parameters: {
|
|
56
|
+
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
57
|
+
controls: {
|
|
58
|
+
matchers: {
|
|
59
|
+
color: /(background|color)$/i,
|
|
60
|
+
date: /Date$/i,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
layout: 'centered',
|
|
64
|
+
docs: {
|
|
65
|
+
theme: customTheme,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default preview
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Themes that should be available in storybook
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const themes = [
|
|
6
|
+
{ name: 'Forvaltning', href: 'css/themes/forvaltning.css' },
|
|
7
|
+
{ name: 'Ledsagerbevis', href: 'css/themes/ledsagerbevis.css' },
|
|
8
|
+
{ name: 'Min kommune', href: 'css/themes/minkommune.css' },
|
|
9
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"emitDecoratorMetadata": true
|
|
5
|
+
},
|
|
6
|
+
"exclude": ["../**/*.spec.ts"],
|
|
7
|
+
"include": [
|
|
8
|
+
"../src/**/*.stories.ts",
|
|
9
|
+
"../src/**/*.stories.js",
|
|
10
|
+
"../src/**/*.stories.jsx",
|
|
11
|
+
"../src/**/*.stories.tsx",
|
|
12
|
+
"../src/**/*.stories.mdx",
|
|
13
|
+
"*.js",
|
|
14
|
+
"*.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# KS Digital Designsystem for Angular
|
|
2
2
|
|
|
3
|
-
> This is
|
|
3
|
+
> ⚠ This library is currently experimental. However, we actively use and test it in internal applications, and we strive to keep it stable at all times.
|
|
4
4
|
|
|
5
5
|
This library provides Angular components for KS Digital, designed to align closely with the components from [Designsystemet.no](https://www.designsystemet.no/komponenter).
|
|
6
6
|
|
|
7
|
-
## Installation
|
|
7
|
+
## Installation
|
|
8
8
|
|
|
9
9
|
Install the required packages using your preferred package manager:
|
|
10
10
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import nx from '@nx/eslint-plugin'
|
|
2
|
+
import baseConfig from '../../eslint.config.mjs'
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
...baseConfig,
|
|
6
|
+
...nx.configs['flat/angular'],
|
|
7
|
+
...nx.configs['flat/angular-template'],
|
|
8
|
+
{
|
|
9
|
+
files: ['**/*.ts'],
|
|
10
|
+
rules: {
|
|
11
|
+
'@angular-eslint/component-class-suffix': 'off',
|
|
12
|
+
'@angular-eslint/directive-class-suffix': 'off',
|
|
13
|
+
'@angular-eslint/directive-selector': [
|
|
14
|
+
'error',
|
|
15
|
+
{
|
|
16
|
+
type: 'attribute',
|
|
17
|
+
prefix: 'ksd',
|
|
18
|
+
style: 'camelCase',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
files: ['**/*.html'],
|
|
25
|
+
// Override or add rules here
|
|
26
|
+
rules: {},
|
|
27
|
+
},
|
|
28
|
+
]
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -5,45 +5,36 @@
|
|
|
5
5
|
"url": "https://github.com/ks-no/designsystem.git",
|
|
6
6
|
"directory": "packages/angular"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.1-alpha.
|
|
8
|
+
"version": "0.0.1-alpha.25",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"private": false,
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
|
-
"type": "module",
|
|
15
|
-
"files": [
|
|
16
|
-
"./dist"
|
|
17
|
-
],
|
|
18
|
-
"main": "./dist/fesm2022/ks-digital-designsystem-angular.mjs",
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
14
|
"dependencies": {
|
|
21
|
-
"@floating-ui/dom": "^1.7.
|
|
22
|
-
"@u-elements/u-details": "^0.1.
|
|
15
|
+
"@floating-ui/dom": "^1.7.4",
|
|
16
|
+
"@u-elements/u-details": "^0.1.5"
|
|
23
17
|
},
|
|
24
18
|
"peerDependencies": {
|
|
25
19
|
"@angular/common": ">=20.0.0",
|
|
26
20
|
"@angular/core": ">=20.0.0"
|
|
27
21
|
},
|
|
28
22
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@angular-eslint/
|
|
33
|
-
"@angular-eslint/
|
|
34
|
-
"@angular-eslint/
|
|
35
|
-
"@angular-eslint/
|
|
36
|
-
"@angular-
|
|
37
|
-
"@
|
|
38
|
-
"@ng-icons/
|
|
39
|
-
"@ng-icons/phosphor-icons": "^32.2.0",
|
|
23
|
+
"@angular-devkit/build-angular": "20.3.9",
|
|
24
|
+
"@angular-eslint/builder": "^20.6.0",
|
|
25
|
+
"@angular-eslint/bundled-angular-compiler": "^20.6.0",
|
|
26
|
+
"@angular-eslint/eslint-plugin": "^20.6.0",
|
|
27
|
+
"@angular-eslint/eslint-plugin-template": "^20.6.0",
|
|
28
|
+
"@angular-eslint/schematics": "^20.6.0",
|
|
29
|
+
"@angular-eslint/template-parser": "^20.6.0",
|
|
30
|
+
"@angular/platform-browser": "20.3.9",
|
|
31
|
+
"@ng-icons/core": "^32.5.0",
|
|
32
|
+
"@ng-icons/phosphor-icons": "^32.5.0",
|
|
40
33
|
"@testing-library/angular": "^17.4.0",
|
|
41
|
-
"@testing-library/jest-dom": "^6.
|
|
42
|
-
"angular-eslint": "^20.
|
|
43
|
-
"jsdom": "~
|
|
44
|
-
"ng-packagr": "^20.
|
|
45
|
-
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "ng-packagr -p ng-package.json"
|
|
34
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
35
|
+
"angular-eslint": "^20.6.0",
|
|
36
|
+
"jsdom": "~27.2.0",
|
|
37
|
+
"ng-packagr": "^20.3.2",
|
|
38
|
+
"zone.js": "~0.15.0"
|
|
48
39
|
}
|
|
49
40
|
}
|
package/project.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ks-digital/designsystem-angular",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/angular/src",
|
|
5
|
+
"prefix": "lib",
|
|
6
|
+
"projectType": "library",
|
|
7
|
+
"tags": [],
|
|
8
|
+
"targets": {
|
|
9
|
+
"build": {
|
|
10
|
+
"executor": "@nx/angular:package",
|
|
11
|
+
"dependsOn": ["@ks-digital/designsystem-themes:build"],
|
|
12
|
+
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
13
|
+
"options": {
|
|
14
|
+
"tsConfig": "packages/angular/tsconfig.lib.prod.json",
|
|
15
|
+
"project": "packages/angular/ng-package.json"
|
|
16
|
+
},
|
|
17
|
+
"configurations": {
|
|
18
|
+
"production": {
|
|
19
|
+
"tsConfig": "packages/angular/tsconfig.lib.prod.json"
|
|
20
|
+
},
|
|
21
|
+
"development": {
|
|
22
|
+
"tsConfig": "packages/angular/tsconfig.lib.json"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"defaultConfiguration": "production"
|
|
26
|
+
},
|
|
27
|
+
"lint": {
|
|
28
|
+
"executor": "@nx/eslint:lint"
|
|
29
|
+
},
|
|
30
|
+
"storybook": {
|
|
31
|
+
"executor": "@analogjs/storybook-angular:start-storybook",
|
|
32
|
+
"options": {
|
|
33
|
+
"port": 4400,
|
|
34
|
+
"configDir": "packages/angular/.storybook",
|
|
35
|
+
"compodoc": false
|
|
36
|
+
},
|
|
37
|
+
"configurations": {
|
|
38
|
+
"ci": {
|
|
39
|
+
"quiet": true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"build-storybook": {
|
|
44
|
+
"executor": "@analogjs/storybook-angular:build-storybook",
|
|
45
|
+
"dependsOn": ["@ks-digital/designsystem-themes:build", "^build"],
|
|
46
|
+
"outputs": ["{options.outputDir}"],
|
|
47
|
+
"options": {
|
|
48
|
+
"outputDir": "dist/storybook/@ks-digital/designsystem-angular",
|
|
49
|
+
"configDir": "packages/angular/.storybook",
|
|
50
|
+
"compodoc": false,
|
|
51
|
+
"experimentalZoneless": true
|
|
52
|
+
},
|
|
53
|
+
"configurations": {
|
|
54
|
+
"ci": {
|
|
55
|
+
"quiet": true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"test-storybook": {
|
|
60
|
+
"executor": "nx:run-commands",
|
|
61
|
+
"options": {
|
|
62
|
+
"command": "test-storybook -c packages/angular/.storybook --url=http://localhost:4400"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"static-storybook": {
|
|
66
|
+
"executor": "@nx/web:file-server",
|
|
67
|
+
"dependsOn": ["build-storybook"],
|
|
68
|
+
"options": {
|
|
69
|
+
"buildTarget": "@ks-digital/designsystem-angular:build-storybook",
|
|
70
|
+
"staticFilePath": "dist/storybook/@ks-digital/designsystem-angular",
|
|
71
|
+
"spa": true,
|
|
72
|
+
"experimentalZoneless": true
|
|
73
|
+
},
|
|
74
|
+
"configurations": {
|
|
75
|
+
"ci": {
|
|
76
|
+
"buildTarget": "@ks-digital/designsystem-angular:build-storybook:ci"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls, Primary } from '@storybook/addon-docs/blocks'
|
|
2
|
+
|
|
3
|
+
import * as AlertStories from './alert.stories'
|
|
4
|
+
|
|
5
|
+
<Meta of={AlertStories} />
|
|
6
|
+
|
|
7
|
+
# Alert
|
|
8
|
+
|
|
9
|
+
Vi bruker `Alert` til å gi brukeren informasjon som det er ekstra viktig at de ser og forstår. Komponenten er designet for å fange brukernes oppmerksomhet. Teksten i varselet skal være kort og tydelig.
|
|
10
|
+
|
|
11
|
+
<Primary />
|
|
12
|
+
<Controls />
|
|
13
|
+
|
|
14
|
+
## Bruk
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
<ksd-alert>En beskjed det er viktig at brukeren ser</ksd-alert>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Kodeeksempler
|
|
21
|
+
|
|
22
|
+
`Alert` kan brukes til fire ulike budskap: Informasjon, suksess, advarsler og feilmelding.
|
|
23
|
+
|
|
24
|
+
### Informasjon
|
|
25
|
+
|
|
26
|
+
Bruk `info` når du vil gi brukeren nøytral og nyttig informasjon.
|
|
27
|
+
|
|
28
|
+
<Canvas of={AlertStories.VariantInfo} />
|
|
29
|
+
|
|
30
|
+
### Suksess
|
|
31
|
+
|
|
32
|
+
Bruk `success` når du vil bekrefte at brukeren har fullført en oppgave, at handlingen var vellykket.
|
|
33
|
+
|
|
34
|
+
<Canvas of={AlertStories.VariantSuccess} />
|
|
35
|
+
|
|
36
|
+
### Advarsel
|
|
37
|
+
|
|
38
|
+
Bruk `warning` når du vil at brukeren skal foreta en bestemt handling eller for å advare dem om noe viktig.
|
|
39
|
+
|
|
40
|
+
<Canvas of={AlertStories.VariantWarning} />
|
|
41
|
+
|
|
42
|
+
### Feilmelding
|
|
43
|
+
|
|
44
|
+
Bruk `danger` for å informere om noe som er kritisk eller som hindrer brukeren i å komme videre.
|
|
45
|
+
|
|
46
|
+
<Canvas of={AlertStories.VariantDanger} />
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NgStyle } from '@angular/common'
|
|
2
|
+
import { render, screen } from '@testing-library/angular'
|
|
3
|
+
import { Alert } from './alert'
|
|
4
|
+
|
|
5
|
+
it('should render children, heading level 1', async () => {
|
|
6
|
+
await render(
|
|
7
|
+
`
|
|
8
|
+
<ksd-alert color="info">
|
|
9
|
+
<h1>Alert me!</h1>
|
|
10
|
+
</ksd-alert>
|
|
11
|
+
`,
|
|
12
|
+
{ imports: [Alert] },
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(
|
|
16
|
+
'Alert me!',
|
|
17
|
+
)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('style should be applied', async () => {
|
|
21
|
+
await render(
|
|
22
|
+
`
|
|
23
|
+
<ksd-alert data-testid="alert" color="info" [ngStyle]="{ color: '#ffcc00' }" class="my-class">
|
|
24
|
+
<h1>Alert me!</h1>
|
|
25
|
+
</ksd-alert>
|
|
26
|
+
`,
|
|
27
|
+
{ imports: [Alert, NgStyle] },
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const alert = screen.getByTestId('alert')
|
|
31
|
+
expect(alert).toHaveStyle({ color: '#ffcc00' })
|
|
32
|
+
expect(alert).toHaveClass('my-class')
|
|
33
|
+
})
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { provideIcons } from '@ng-icons/core'
|
|
2
|
+
import { phosphorPencilLine } from '@ng-icons/phosphor-icons/regular'
|
|
3
|
+
import {
|
|
4
|
+
componentWrapperDecorator,
|
|
5
|
+
moduleMetadata,
|
|
6
|
+
type Meta,
|
|
7
|
+
type StoryObj,
|
|
8
|
+
} from '@storybook/angular'
|
|
9
|
+
import { CommonArgs } from '../../../.storybook/default-args'
|
|
10
|
+
import { SeverityColors } from '../colors'
|
|
11
|
+
import { Paragraph } from '../paragraph/paragraph'
|
|
12
|
+
import { Alert } from './alert'
|
|
13
|
+
|
|
14
|
+
const SEVERITY_COLORS: SeverityColors[] = [
|
|
15
|
+
'info',
|
|
16
|
+
'success',
|
|
17
|
+
'warning',
|
|
18
|
+
'danger',
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
type AlertArgs = CommonArgs & {
|
|
22
|
+
variant: 'default' | 'tinted'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const meta: Meta<AlertArgs> = {
|
|
26
|
+
component: Alert,
|
|
27
|
+
title: 'Komponenter/Alert',
|
|
28
|
+
argTypes: {
|
|
29
|
+
'data-size': {
|
|
30
|
+
options: ['sm', 'md', 'lg'],
|
|
31
|
+
control: { type: 'radio' },
|
|
32
|
+
},
|
|
33
|
+
'data-color': {
|
|
34
|
+
options: SEVERITY_COLORS,
|
|
35
|
+
control: { type: 'radio' },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
decorators: [
|
|
39
|
+
moduleMetadata({
|
|
40
|
+
imports: [Alert, Paragraph],
|
|
41
|
+
providers: [provideIcons({ phosphorPencilLine })],
|
|
42
|
+
}),
|
|
43
|
+
componentWrapperDecorator(
|
|
44
|
+
(story) =>
|
|
45
|
+
`<div style="display:flex;flex-direction:row;justify-content:center;align-items:center;flex-wrap:wrap;gap:var(--ds-size-4)">${story}</div>`,
|
|
46
|
+
),
|
|
47
|
+
],
|
|
48
|
+
}
|
|
49
|
+
export default meta
|
|
50
|
+
type Story = StoryObj<AlertArgs>
|
|
51
|
+
|
|
52
|
+
export const Preview: Story = {
|
|
53
|
+
render: (args) => ({
|
|
54
|
+
props: args,
|
|
55
|
+
template: `
|
|
56
|
+
<ksd-alert>
|
|
57
|
+
En beskjed det er viktig at brukeren ser
|
|
58
|
+
</ksd-alert>
|
|
59
|
+
`,
|
|
60
|
+
}),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const VariantInfo: Story = {
|
|
64
|
+
args: {},
|
|
65
|
+
render: (args) => ({
|
|
66
|
+
props: args,
|
|
67
|
+
template: `
|
|
68
|
+
<ksd-alert data-color="info">
|
|
69
|
+
<h2 class="ds-heading" data-size="xs" style="margin-bottom: var(--ds-size-2)">
|
|
70
|
+
Har du husket å bestille passtime?
|
|
71
|
+
</h2>
|
|
72
|
+
|
|
73
|
+
<p ksd-paragraph>
|
|
74
|
+
Det er lange køer for å bestille pass om dagen, det kan være lurt å
|
|
75
|
+
bestille i god tid før du skal reise.
|
|
76
|
+
</p>
|
|
77
|
+
</ksd-alert>
|
|
78
|
+
`,
|
|
79
|
+
}),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const VariantWarning: Story = {
|
|
83
|
+
args: {},
|
|
84
|
+
render: (args) => ({
|
|
85
|
+
props: args,
|
|
86
|
+
template: `
|
|
87
|
+
<ksd-alert data-color="warning">
|
|
88
|
+
<h2 class="ds-heading" data-size="xs" style="margin-bottom: var(--ds-size-2)">
|
|
89
|
+
Vi har tekniske problemer
|
|
90
|
+
</h2>
|
|
91
|
+
|
|
92
|
+
<p ksd-paragraph>
|
|
93
|
+
Det gjør at du kan bli avbrutt mens du fyller ut skjemaet. Vi jobber med å
|
|
94
|
+
rette problemene.
|
|
95
|
+
</p>
|
|
96
|
+
</ksd-alert>
|
|
97
|
+
`,
|
|
98
|
+
}),
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const VariantDanger: Story = {
|
|
102
|
+
args: {},
|
|
103
|
+
render: (args) => ({
|
|
104
|
+
props: args,
|
|
105
|
+
template: `
|
|
106
|
+
<ksd-alert data-color="danger">
|
|
107
|
+
<h2 class="ds-heading" data-size="xs" style="margin-bottom: var(--ds-size-2)">
|
|
108
|
+
Det har skjedd en feil
|
|
109
|
+
</h2>
|
|
110
|
+
|
|
111
|
+
<p ksd-paragraph>
|
|
112
|
+
Vi klarer ikke å hente informasjonen du ser etter akkurat nå. Prøv igjen
|
|
113
|
+
litt senere. Hvis vi fortsatt ikke klarer å vise informasjonen du trenger,
|
|
114
|
+
tar du kontakt med kundeservice på telefon 85 44 32 66.
|
|
115
|
+
</p>
|
|
116
|
+
</ksd-alert>
|
|
117
|
+
`,
|
|
118
|
+
}),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const VariantSuccess: Story = {
|
|
122
|
+
args: {},
|
|
123
|
+
render: (args) => ({
|
|
124
|
+
props: args,
|
|
125
|
+
template: `
|
|
126
|
+
<ksd-alert data-color="success">
|
|
127
|
+
<h2 class="ds-heading" data-size="xs" style="margin-bottom: var(--ds-size-2)">
|
|
128
|
+
Gratulerer! Du kan nå starte selskapet ditt
|
|
129
|
+
</h2>
|
|
130
|
+
|
|
131
|
+
<p ksd-paragraph>
|
|
132
|
+
Det ser ut til at regnestykket går i pluss og at du har det som skal til
|
|
133
|
+
for å starte selskapet ditt.
|
|
134
|
+
</p>
|
|
135
|
+
</ksd-alert>
|
|
136
|
+
`,
|
|
137
|
+
}),
|
|
138
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Component, input } from '@angular/core'
|
|
2
|
+
import { SeverityColors } from '../colors'
|
|
3
|
+
import { CommonInputs } from '../common-inputs'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Alerts are used to inform users about important information, warnings, errors, or success.
|
|
7
|
+
*/
|
|
8
|
+
@Component({
|
|
9
|
+
selector: 'ksd-alert',
|
|
10
|
+
template: ` <ng-content />`,
|
|
11
|
+
host: {
|
|
12
|
+
class: 'ds-alert',
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* Use Phosphor Icons
|
|
16
|
+
*/
|
|
17
|
+
styles: `
|
|
18
|
+
:host {
|
|
19
|
+
--dsc-alert-icon-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Cpath d='M128,24A104,104,0,1,0,232,128A104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z'/%3E%3C/svg%3E");
|
|
20
|
+
}
|
|
21
|
+
:host[data-color='warning'] {
|
|
22
|
+
--dsc-alert-icon-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Cpath d='M120,136V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0ZM232,91.55v72.9a15.86,15.86,0,0,1-4.69,11.31l-51.55,51.55A15.86,15.86,0,0,1,164.45,232H91.55a15.86,15.86,0,0,1-11.31-4.69L28.69,175.76A15.86,15.86,0,0,1,24,164.45V91.55a15.86,15.86,0,0,1,4.69-11.31L80.24,28.69A15.86,15.86,0,0,1,91.55,24h72.9a15.86,15.86,0,0,1,11.31,4.69l51.55,51.55A15.86,15.86,0,0,1,232,91.55Zm-16,0L164.45,40H91.55L40,91.55v72.9L91.55,216h72.9L216,164.45ZM128,160a12,12,0,1,0,12,12A12,12,0,0,0,128,160Z'/%3E%3C/svg%3E");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
:host[data-color='success'] {
|
|
26
|
+
--dsc-alert-icon-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Cpath d='M173.66,98.34a8,8,0,0,1,0,11.32l-56,56a8,8,0,0,1-11.32,0l-24-24a8,8,0,0,1,11.32-11.32L112,148.69l50.34-50.35A8,8,0,0,1,173.66,98.34ZM232,128A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z'%3E%3C/path%3E%3C/svg%3E");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
:host[data-color='danger'] {
|
|
30
|
+
--dsc-alert-icon-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Cpath d='M165.66,101.66,139.31,128l26.35,26.34a8,8,0,0,1-11.32,11.32L128,139.31l-26.34,26.35a8,8,0,0,1-11.32-11.32L116.69,128,90.34,101.66a8,8,0,0,1,11.32-11.32L128,116.69l26.34-26.35a8,8,0,0,1,11.32,11.32ZM232,128A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z'%3E%3C/path%3E%3C/svg%3E");
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
hostDirectives: [
|
|
34
|
+
{
|
|
35
|
+
directive: CommonInputs,
|
|
36
|
+
inputs: ['data-size'],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
export class Alert {
|
|
41
|
+
/**
|
|
42
|
+
* The color variant of the alert.
|
|
43
|
+
*/
|
|
44
|
+
/* eslint-disable-next-line @angular-eslint/no-input-rename */
|
|
45
|
+
dataColor = input<SeverityColors>(undefined, { alias: 'data-color' })
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Alert } from './alert'
|