@helsenorge/lightbox 8.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.
@@ -0,0 +1,23 @@
1
+ import { globSync } from 'glob';
2
+
3
+ const getEntryName = name => {
4
+ return name.replace(/^src[/\\]/, '').replace(/\.tsx?$/, '');
5
+ };
6
+
7
+ const createEntries = (entryList, entry) => {
8
+ const name = getEntryName(entry);
9
+
10
+ if (name in entryList) {
11
+ throw new Error(`${name} finnes flere ganger i listen med entries`);
12
+ }
13
+ entryList[name] = entry;
14
+
15
+ return entryList;
16
+ };
17
+
18
+ export const alwaysIgnore = ['**/__snapshots__/**/*', '**/*.stories.tsx', '**/*.test.tsx', '**/*.scss', '**/*.scss.d.ts', '**/*.d.ts'];
19
+
20
+ const components = globSync(`src/components/**/index.{ts,tsx}`, { ignore: alwaysIgnore });
21
+ const hooksAndExtras = globSync(`src/**/*.{ts,tsx}`, { ignore: [...alwaysIgnore, 'src/components/**/*'] });
22
+
23
+ export const entries = [...components, ...hooksAndExtras].sort((a, b) => a.localeCompare(b)).reduce(createEntries, {});
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@helsenorge/lightbox",
3
+ "sideEffects": false,
4
+ "private": false,
5
+ "version": "8.0.0",
6
+ "description": "The official Helsenorge lightbox.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/helsenorge/designsystem.git"
10
+ },
11
+ "homepage": "https://helsenorge.design",
12
+ "author": "Helsenorge",
13
+ "maintainers": [
14
+ "ROX"
15
+ ],
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "publishConfig": {
19
+ "directory": "lib",
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "prebuild": "npm-run-all clean generate:cssdefinitions generate:tsdefinitions",
24
+ "build": "vite build",
25
+ "clean": "rimraf lib types",
26
+ "generate:cssdefinitions": "typed-scss-modules \"src/**/*.module.scss\" --nameFormat none --exportType default --includePaths node_modules ../../node_modules",
27
+ "generate:tsdefinitions": "tsc --noEmit false --declaration --emitDeclarationOnly --declarationDir types",
28
+ "eslint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
29
+ "eslint:fix": "npm run eslint -- --fix",
30
+ "stylelint": "stylelint \"src/**/*.{css,scss}\"",
31
+ "stylelint:fix": "npm run stylelint -- --fix",
32
+ "prettier": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,scss,md,json}\"",
33
+ "prettier:fix": "npm run prettier -- --write",
34
+ "pretypecheck": "tsc -v",
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest"
37
+ },
38
+ "peerDependencies": {
39
+ "@helsenorge/designsystem-react": "^8.0.0",
40
+ "classnames": "^2.5.1",
41
+ "react": "^17.0.0 || ^18.0.0",
42
+ "react-dom": "^17.0.0 || ^18.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@helsenorge/designsystem-react": "^8.0.0",
46
+ "@rollup/plugin-replace": "^5.0.7",
47
+ "@testing-library/react": "^16.0.0",
48
+ "@testing-library/user-event": "^14.5.2",
49
+ "@types/react": "^18.3.3",
50
+ "@types/react-dom": "^18.3.0",
51
+ "@vitejs/plugin-react": "^4.3.1",
52
+ "@vitest/coverage-istanbul": "^2.0.5",
53
+ "@vitest/coverage-v8": "^2.0.5",
54
+ "bootstrap": "^4.6.2",
55
+ "classnames": "^2.5.1",
56
+ "jsdom": "^24.1.1",
57
+ "react": "^18.3.1",
58
+ "react-dom": "^18.3.1",
59
+ "react-zoom-pan-pinch": "^3.6.1",
60
+ "rollup-plugin-copy": "^3.5.0",
61
+ "rollup-plugin-generate-package-json": "^3.2.0",
62
+ "rollup-plugin-peer-deps-external": "^2.2.4",
63
+ "typed-scss-modules": "^8.0.1",
64
+ "typescript": "~5.5.4",
65
+ "vite": "^5.4.0",
66
+ "vitest": "^2.0.5"
67
+ }
68
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+
3
+ import { action } from '@storybook/addon-actions';
4
+ import { StoryObj, Meta } from '@storybook/react';
5
+
6
+ import Docs from '@helsenorge/designsystem-react/docs';
7
+
8
+ import LightBox from './LightBox';
9
+
10
+ const meta = {
11
+ title: '@helsenorge/lightbox/LightBox',
12
+ component: LightBox,
13
+ parameters: {
14
+ docs: {
15
+ description: {
16
+ component: 'Beskrivelse av LightBox',
17
+ },
18
+ page: (): React.JSX.Element => <Docs component={LightBox} />,
19
+ },
20
+ },
21
+ args: {
22
+ ariaLabelCloseButton: 'Lukk Lightbox',
23
+ ariaLabelLeftArrow: 'Forrige bilde',
24
+ ariaLabelLightBox: 'Bildevisning',
25
+ ariaLabelRightArrow: 'Neste bilde',
26
+ ariaLabelCloseTextBox: 'Lukk tekstboks',
27
+ ariaLabelOpenTextBox: 'Åpne tekstboks',
28
+ ariaLabelZoomIn: 'Zoom inn',
29
+ ariaLabelZoomOut: 'Zoom ut',
30
+ ariaLabelZoomSlider: 'Zoom',
31
+ closeTextAfterSeconds: 3,
32
+ imageAlt: 'A random cat',
33
+ imageSrc: 'https://loremflickr.com/640/480',
34
+ testId: 'lightBox',
35
+ imageText: 'En søt pus eller kanskje flere',
36
+ onClose: action('Close button clicked'),
37
+ onLeftArrowClick: action('Left arrow clicked'),
38
+ onRightArrowClick: action('Right arrow clicked'),
39
+ },
40
+ argTypes: {},
41
+ } satisfies Meta<typeof LightBox>;
42
+
43
+ export default meta;
44
+
45
+ type Story = StoryObj<typeof meta>;
46
+
47
+ export const Default: Story = {
48
+ render: args => <LightBox {...args} />,
49
+ };
50
+
51
+ export const LangBildetekst: Story = {
52
+ render: args => (
53
+ <LightBox
54
+ {...args}
55
+ imageText={
56
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu turpis posuere, dignissim ex at, interdum metus. Etiam efficitur ut lectus et condimentum. Suspendisse ornare suscipit metus sit amet luctus. Quisque risus orci, molestie sit amet tempus non, semper a ligula. Etiam volutpat scelerisque magna vel feugiat. Sed ac venenatis justo. Aliquam iaculis ante a eros sagittis, id gravida felis placerat. Cras luctus mi quam, non venenatis lorem condimentum vel. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Integer nulla sem, placerat non blandit ac, interdum vel augue. Nulla fermentum orci non augue pulvinar, sed posuere neque scelerisque. Aenean pulvinar commodo lorem vel consectetur. Nam augue lectus, tempus vitae finibus id, dignissim id eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pulvinar commodo lorem vel consectetur. Nam augue lectus, tempus vitae finibus id, dignissim id eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
57
+ }
58
+ closeTextAfterSeconds={undefined}
59
+ />
60
+ ),
61
+ };
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+
3
+ import { render, screen, fireEvent } from '@testing-library/react';
4
+ import { vi } from 'vitest';
5
+
6
+ import LightBox from './LightBox';
7
+
8
+ describe('Gitt at LightBox skal vises', (): void => {
9
+ describe('Når LightBox vises', (): void => {
10
+ test('Så vises LightBox', (): void => {
11
+ render(
12
+ <LightBox
13
+ ariaLabelCloseButton={''}
14
+ ariaLabelLeftArrow={''}
15
+ ariaLabelRightArrow={''}
16
+ ariaLabelCloseTextBox={''}
17
+ ariaLabelOpenTextBox={''}
18
+ imageAlt={''}
19
+ imageSrc={''}
20
+ onClose={() => null}
21
+ ariaLabelZoomOut={''}
22
+ ariaLabelZoomIn={''}
23
+ />
24
+ );
25
+ });
26
+
27
+ test('Så vises lukkeknapp med riktig label', (): void => {
28
+ render(
29
+ <LightBox
30
+ ariaLabelCloseButton="Lukk"
31
+ ariaLabelLeftArrow=""
32
+ ariaLabelRightArrow=""
33
+ ariaLabelCloseTextBox=""
34
+ ariaLabelOpenTextBox=""
35
+ imageAlt=""
36
+ imageSrc=""
37
+ onClose={() => null}
38
+ ariaLabelZoomOut=""
39
+ ariaLabelZoomIn=""
40
+ />
41
+ );
42
+
43
+ const closeButton = screen.getByLabelText('Lukk');
44
+ expect(closeButton).toBeInTheDocument();
45
+ });
46
+
47
+ test('Så vises begge pilknapper når callback er gitt', (): void => {
48
+ render(
49
+ <LightBox
50
+ ariaLabelCloseButton=""
51
+ ariaLabelLeftArrow="Forrige bilde"
52
+ onLeftArrowClick={() => null}
53
+ ariaLabelRightArrow="Neste bilde"
54
+ onRightArrowClick={() => null}
55
+ ariaLabelCloseTextBox=""
56
+ ariaLabelOpenTextBox=""
57
+ imageAlt=""
58
+ imageSrc=""
59
+ onClose={() => null}
60
+ ariaLabelZoomOut=""
61
+ ariaLabelZoomIn=""
62
+ />
63
+ );
64
+
65
+ const rightArrow = screen.getByLabelText('Neste bilde');
66
+ const leftArrow = screen.getByLabelText('Forrige bilde');
67
+ expect(rightArrow).toBeInTheDocument();
68
+ expect(leftArrow).toBeInTheDocument();
69
+ });
70
+
71
+ test('Så blir onClose funksjonen kalt når lukkeknappen trykkes', (): void => {
72
+ const onCloseMock = vi.fn();
73
+ render(
74
+ <LightBox
75
+ ariaLabelCloseButton="Lukk"
76
+ ariaLabelLeftArrow=""
77
+ ariaLabelRightArrow=""
78
+ ariaLabelCloseTextBox=""
79
+ ariaLabelOpenTextBox=""
80
+ imageAlt=""
81
+ imageSrc=""
82
+ onClose={onCloseMock}
83
+ ariaLabelZoomOut=""
84
+ ariaLabelZoomIn=""
85
+ />
86
+ );
87
+ const closeButton = screen.getByLabelText('Lukk');
88
+ fireEvent.click(closeButton);
89
+ expect(onCloseMock).toHaveBeenCalled();
90
+ });
91
+ });
92
+ });
@@ -0,0 +1,265 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+
3
+ import classNames from 'classnames';
4
+ import { TransformWrapper, TransformComponent, useTransformComponent } from 'react-zoom-pan-pinch';
5
+
6
+ import Icon from '@helsenorge/designsystem-react/components/Icon';
7
+ import ChevronLeft from '@helsenorge/designsystem-react/components/Icons/ChevronLeft';
8
+ import ChevronRight from '@helsenorge/designsystem-react/components/Icons/ChevronRight';
9
+ import ChevronsDown from '@helsenorge/designsystem-react/components/Icons/ChevronsDown';
10
+ import ChevronsUp from '@helsenorge/designsystem-react/components/Icons/ChevronsUp';
11
+ import Minus from '@helsenorge/designsystem-react/components/Icons/Minus';
12
+ import PlusSmall from '@helsenorge/designsystem-react/components/Icons/PlusSmall';
13
+ import X from '@helsenorge/designsystem-react/components/Icons/X';
14
+ import { IconSize, KeyboardEventKey, ZIndex } from '@helsenorge/designsystem-react/constants';
15
+ import { useSize } from '@helsenorge/designsystem-react/hooks/useSize';
16
+
17
+ import { useKeyboardEvent } from '@helsenorge/designsystem-react';
18
+
19
+ import MiniSlider from './MiniSlider';
20
+
21
+ import styles from './styles.module.scss';
22
+
23
+ export interface LightBoxProps {
24
+ /** Aria label for the close button */
25
+ ariaLabelCloseButton: string;
26
+ /** Aria label for the text box button when its open */
27
+ ariaLabelCloseTextBox: string;
28
+ /** Aria label for the left arrow button */
29
+ ariaLabelLeftArrow: string;
30
+ /** Aria label for the full modal describing what the modal contains */
31
+ ariaLabelLightBox: string;
32
+ /** Aria label for the right arrow button */
33
+ ariaLabelRightArrow: string;
34
+ /** Aria label for the text box button when its closed */
35
+ ariaLabelOpenTextBox: string;
36
+ /** Aria label for the zoom in button */
37
+ ariaLabelZoomIn: string;
38
+ /** Aria label for the zoom out button */
39
+ ariaLabelZoomOut: string;
40
+ /** Aria label for the slider input component */
41
+ ariaLabelZoomSlider: string;
42
+ /** If set the text box closes automatically after the given seconds */
43
+ closeTextAfterSeconds?: number;
44
+ /** Alt text for the image */
45
+ imageAlt: string;
46
+ /** Source of the image that will be shown */
47
+ imageSrc: string;
48
+ /** The text for the image that shows in the textbox */
49
+ imageText?: string;
50
+ /** Function is called when user clicks the close button */
51
+ onClose: () => void;
52
+ /** Function is called when user clicks the left arrow button. If not given the arrow will not show. */
53
+ onLeftArrowClick?: () => void;
54
+ /** Function is called when user clicks the right arrow button. If not given the arrow will not show. */
55
+ onRightArrowClick?: () => void;
56
+ /** Sets the data-testid attribute. */
57
+ testId?: string;
58
+ }
59
+
60
+ const LightBox: React.FC<LightBoxProps> = ({
61
+ ariaLabelCloseButton,
62
+ ariaLabelLeftArrow,
63
+ ariaLabelLightBox,
64
+ ariaLabelRightArrow,
65
+ ariaLabelCloseTextBox,
66
+ ariaLabelOpenTextBox,
67
+ ariaLabelZoomIn,
68
+ ariaLabelZoomOut,
69
+ ariaLabelZoomSlider,
70
+ closeTextAfterSeconds,
71
+ imageAlt,
72
+ imageSrc,
73
+ imageText,
74
+ onClose,
75
+ onLeftArrowClick,
76
+ onRightArrowClick,
77
+ testId,
78
+ }) => {
79
+ const [imageTextOpen, setImageTextOpen] = React.useState(true);
80
+ const lightBoxRef = useRef<HTMLDivElement>(null);
81
+ const textBoxRef = useRef<HTMLParagraphElement>(null);
82
+ const { height: textBoxHeight = 0 } = useSize(textBoxRef) || {};
83
+ const [zoom, setZoom] = useState(1.0);
84
+
85
+ useKeyboardEvent(lightBoxRef, onClose, [KeyboardEventKey.Escape]);
86
+
87
+ const updateStates = (newZoom: number): void => {
88
+ if (zoom === newZoom) return;
89
+ setZoom(newZoom);
90
+ };
91
+
92
+ useEffect(() => {
93
+ if (!closeTextAfterSeconds) return;
94
+ const timer = setTimeout(() => {
95
+ setImageTextOpen(false);
96
+ }, closeTextAfterSeconds * 1000);
97
+
98
+ return () => clearTimeout(timer);
99
+ }, []);
100
+
101
+ return (
102
+ <div
103
+ data-testid={testId}
104
+ className={styles.lightBox}
105
+ style={{ zIndex: ZIndex.OverlayScreen }}
106
+ role="dialog"
107
+ aria-modal={true}
108
+ aria-label={ariaLabelLightBox}
109
+ ref={lightBoxRef}
110
+ >
111
+ <button
112
+ onClick={onClose}
113
+ aria-label={ariaLabelCloseButton}
114
+ data-testid="closeButton"
115
+ className={classNames(styles.button, styles['close-button'])}
116
+ style={{ zIndex: ZIndex.LightBoxButtons }}
117
+ >
118
+ <Icon svgIcon={X} color="white" size={IconSize.XSmall} />
119
+ </button>
120
+ {onLeftArrowClick && (
121
+ <button
122
+ className={classNames(styles.button, styles['arrow-button'], styles['arrow-button--left'])}
123
+ onClick={onLeftArrowClick}
124
+ aria-label={ariaLabelLeftArrow}
125
+ data-testid="leftArrow"
126
+ style={{ zIndex: ZIndex.LightBoxButtons }}
127
+ >
128
+ <Icon svgIcon={ChevronLeft} color="white" size={IconSize.XSmall} />
129
+ </button>
130
+ )}
131
+ {onRightArrowClick && (
132
+ <button
133
+ className={classNames(styles.button, styles['arrow-button'], styles['arrow-button--right'])}
134
+ onClick={onRightArrowClick}
135
+ aria-label={ariaLabelRightArrow}
136
+ data-testid="rightarrow"
137
+ style={{ zIndex: ZIndex.LightBoxButtons }}
138
+ >
139
+ <Icon svgIcon={ChevronRight} color="white" size={IconSize.XSmall} />
140
+ </button>
141
+ )}
142
+ {imageText && (
143
+ <div
144
+ className={styles['image-text-box']}
145
+ style={{ bottom: imageTextOpen ? '0' : '-' + textBoxHeight + 'px', transition: '0.5s', zIndex: ZIndex.LightBoxButtons }}
146
+ >
147
+ <button
148
+ className={classNames(styles.button, styles['image-text-box__button'])}
149
+ onClick={() => setImageTextOpen(!imageTextOpen)}
150
+ style={{ zIndex: ZIndex.LightBoxButtons }}
151
+ aria-label={imageTextOpen ? ariaLabelCloseTextBox : ariaLabelOpenTextBox}
152
+ aria-expanded={imageTextOpen}
153
+ >
154
+ {imageTextOpen ? (
155
+ <Icon svgIcon={ChevronsDown} color="white" size={IconSize.XSmall} />
156
+ ) : (
157
+ <Icon svgIcon={ChevronsUp} color="white" size={IconSize.XSmall} />
158
+ )}
159
+ </button>
160
+ <div>
161
+ <p ref={textBoxRef} className={styles['image-text-box__text']}>
162
+ {imageText}
163
+ </p>
164
+ <div className={styles['image-text-box__overflow-border']}></div>
165
+ </div>
166
+ </div>
167
+ )}
168
+ <TransformWrapper initialScale={1} maxScale={4} doubleClick={{ mode: 'toggle', step: 4 }}>
169
+ {({ setTransform }) => (
170
+ <>
171
+ <Controls
172
+ transform={setTransform}
173
+ updateStates={updateStates}
174
+ zoom={zoom}
175
+ ariaLabelZoomIn={ariaLabelZoomIn}
176
+ ariaLabelZoomOut={ariaLabelZoomOut}
177
+ ariaLabelZoomSlider={ariaLabelZoomSlider}
178
+ />
179
+ <TransformComponent
180
+ wrapperStyle={{
181
+ zIndex: 1,
182
+ width: '100%',
183
+ height: '100%',
184
+ }}
185
+ contentStyle={{
186
+ width: '100%',
187
+ height: '100%',
188
+ }}
189
+ >
190
+ <img src={imageSrc} alt={imageAlt} />
191
+ </TransformComponent>
192
+ </>
193
+ )}
194
+ </TransformWrapper>
195
+ </div>
196
+ );
197
+ };
198
+
199
+ const Controls = ({
200
+ transform,
201
+ updateStates,
202
+ zoom,
203
+ ariaLabelZoomIn,
204
+ ariaLabelZoomOut,
205
+ ariaLabelZoomSlider,
206
+ }: {
207
+ transform: (newPositionX: number, newPositionY: number, newScale: number, animationTime?: number | undefined) => void;
208
+ updateStates: (newZoom: number) => void;
209
+ zoom: number;
210
+ ariaLabelZoomIn: string;
211
+ ariaLabelZoomOut: string;
212
+ ariaLabelZoomSlider: string;
213
+ }): React.JSX.Element => {
214
+ useTransformComponent(({ state }) => {
215
+ updateStates(state.scale);
216
+ });
217
+
218
+ const calculateZoomCenter = (newScale: number): number[] => {
219
+ const element = document.getElementsByClassName('react-transform-component')[0];
220
+ const style = window.getComputedStyle(element);
221
+ const matrix = new WebKitCSSMatrix(style.transform);
222
+
223
+ const ratio = (newScale - zoom) / zoom + 1;
224
+ const x = (matrix.m41 - (window.innerWidth / 2) * (1 - zoom / newScale)) * ratio;
225
+ const y = (matrix.m42 - (window.innerHeight / 2) * (1 - zoom / newScale)) * ratio;
226
+ return [x, y];
227
+ };
228
+
229
+ const adjustZoom = (newScale: number | undefined): void => {
230
+ if (newScale === undefined || newScale === zoom) return;
231
+ if (newScale < 1) newScale = 1;
232
+ if (newScale > 4) newScale = 4;
233
+ const [x, y] = calculateZoomCenter(newScale);
234
+ transform(x, y, newScale, 1);
235
+ };
236
+
237
+ const adjustZoomWithAnimation = (newScale: number | undefined): void => {
238
+ if (newScale === undefined || newScale === zoom) return;
239
+ if (newScale < 1) newScale = 1;
240
+ if (newScale > 4) newScale = 4;
241
+ const [x, y] = calculateZoomCenter(newScale);
242
+ transform(x, y, newScale);
243
+ };
244
+
245
+ return (
246
+ <div className={classNames(styles['zoom-buttons'])} style={{ zIndex: ZIndex.LightBoxButtons }}>
247
+ <button className={classNames(styles.button)} onClick={() => adjustZoomWithAnimation(zoom - 0.5)} aria-label={ariaLabelZoomOut}>
248
+ <Icon svgIcon={Minus} color="white" size={IconSize.XSmall} />
249
+ </button>
250
+ <MiniSlider
251
+ className={styles['slider']}
252
+ minValue={1}
253
+ maxValue={4}
254
+ onChange={adjustZoom}
255
+ value={zoom}
256
+ ariaLabel={ariaLabelZoomSlider}
257
+ />
258
+ <button className={classNames(styles.button)} onClick={() => adjustZoomWithAnimation(zoom + 0.5)} aria-label={ariaLabelZoomIn}>
259
+ <Icon svgIcon={PlusSmall} color="white" size={IconSize.XSmall} />
260
+ </button>
261
+ </div>
262
+ );
263
+ };
264
+
265
+ export default LightBox;
@@ -0,0 +1,37 @@
1
+ import React, { ChangeEvent } from 'react';
2
+
3
+ interface MiniSliderProps {
4
+ value: number;
5
+ minValue: number;
6
+ maxValue: number;
7
+ onChange: (newValue: number) => void;
8
+ className?: string;
9
+ ariaLabel: string;
10
+ }
11
+
12
+ const MiniSlider = (props: MiniSliderProps): React.JSX.Element => {
13
+ const handleOnChange = (event: ChangeEvent<HTMLInputElement>): void => {
14
+ event.preventDefault();
15
+ const newValue = parseFloat(event.target.value);
16
+ props.onChange(newValue);
17
+ };
18
+
19
+ return (
20
+ <div className={props.className}>
21
+ <input
22
+ onChange={handleOnChange}
23
+ type="range"
24
+ min={props.minValue}
25
+ max={props.maxValue}
26
+ value={props.value}
27
+ aria-valuenow={props.value}
28
+ aria-valuemin={props.minValue}
29
+ aria-valuemax={props.maxValue}
30
+ aria-label={props.ariaLabel}
31
+ step={0.1}
32
+ />
33
+ </div>
34
+ );
35
+ };
36
+
37
+ export default MiniSlider;
@@ -0,0 +1,3 @@
1
+ import LightBox from './LightBox';
2
+ export * from './LightBox';
3
+ export default LightBox;
@@ -0,0 +1,139 @@
1
+ @import '@helsenorge/designsystem-react/scss/supernova/styles/colors';
2
+
3
+ .lightBox {
4
+ display: flex;
5
+ justify-content: center;
6
+ align-items: center;
7
+ background-color: var(--core-color-black);
8
+ position: fixed;
9
+ top: 0;
10
+ left: 0;
11
+ width: 100vw;
12
+ height: 100dvh;
13
+ }
14
+
15
+ .lightBox img {
16
+ width: 100%;
17
+ height: 100%;
18
+ object-fit: contain;
19
+ }
20
+
21
+ .button {
22
+ background-color: var(--core-color-black);
23
+ color: var(--color-base-text-ondark);
24
+ display: flex;
25
+ justify-content: center;
26
+ border: 0;
27
+
28
+ &:hover {
29
+ background-color: var(--color-action-background-transparent-ondark-hover);
30
+ outline: 1px solid var(--color-action-border-ondark-hover);
31
+ }
32
+
33
+ &:focus-visible {
34
+ background-color: var(--color-action-background-transparent-ondark-hoverselected);
35
+ outline: 2px solid var(--color-action-border-ondark-focus);
36
+ }
37
+ }
38
+
39
+ .slider {
40
+ color: var(--core-color-white);
41
+ display: flex;
42
+ cursor: ew-resize;
43
+ align-items: center;
44
+
45
+ input[type='range'] {
46
+ appearance: none;
47
+ height: 2px;
48
+ background: var(--core-color-white);
49
+ border-radius: 5px;
50
+ }
51
+
52
+ input[type='range']::-webkit-slider-thumb {
53
+ appearance: none;
54
+ height: 12px;
55
+ width: 12px;
56
+ border-radius: 50%;
57
+ background: var(--core-color-white);
58
+ cursor: ew-resize;
59
+ box-shadow: 0 0 2px 0 #555;
60
+ }
61
+
62
+ input[type='range']::-webkit-slider-runnable-track {
63
+ appearance: none;
64
+ box-shadow: none;
65
+ border: none;
66
+ background: transparent;
67
+ }
68
+ }
69
+
70
+ .zoom-buttons {
71
+ position: absolute;
72
+ top: 0;
73
+ display: flex;
74
+ flex-flow: row;
75
+ align-items: center;
76
+ justify-content: center;
77
+ background-color: var(--core-color-black);
78
+ color: var(--color-base-text-ondark);
79
+ padding: 0.1rem;
80
+ border-radius: 0 0 4px 4px;
81
+ font-size: 1.5rem;
82
+ }
83
+
84
+ .close-button {
85
+ position: absolute;
86
+ top: 0;
87
+ right: 0;
88
+ border-radius: 4px;
89
+ }
90
+
91
+ .arrow-button {
92
+ position: absolute;
93
+
94
+ // top: 50dvh;
95
+ width: 2.375rem;
96
+
97
+ &--left {
98
+ left: 0;
99
+ border-radius: 0 4px 4px 0;
100
+ }
101
+
102
+ &--right {
103
+ right: 0;
104
+ border-radius: 4px 0 0 4px;
105
+ }
106
+ }
107
+
108
+ .image-text-box {
109
+ position: absolute;
110
+ bottom: 0;
111
+ width: 100%;
112
+
113
+ &__button {
114
+ outline: none;
115
+ border: none;
116
+ position: relative;
117
+ left: 50%;
118
+ transform: translateX(-50%);
119
+ width: 2.5rem;
120
+ border-radius: 4px 4px 0 0;
121
+ }
122
+
123
+ &__text {
124
+ color: var(--color-base-text-ondark);
125
+ background-color: var(--core-color-black);
126
+ margin: 0;
127
+ padding: 0.75rem 1rem;
128
+ max-height: calc(50dvh - 19px);
129
+ overflow: auto;
130
+ }
131
+
132
+ &__overflow-border {
133
+ position: absolute;
134
+ bottom: 0;
135
+ width: 100%;
136
+ height: 1.5rem;
137
+ background: linear-gradient(#0000, var(--core-color-black));
138
+ }
139
+ }
@@ -0,0 +1,20 @@
1
+ export type Styles = {
2
+ 'arrow-button': string;
3
+ 'arrow-button--left': string;
4
+ 'arrow-button--right': string;
5
+ button: string;
6
+ 'close-button': string;
7
+ 'image-text-box': string;
8
+ 'image-text-box__button': string;
9
+ 'image-text-box__overflow-border': string;
10
+ 'image-text-box__text': string;
11
+ lightBox: string;
12
+ slider: string;
13
+ 'zoom-buttons': string;
14
+ };
15
+
16
+ export type ClassNames = keyof Styles;
17
+
18
+ declare const styles: Styles;
19
+
20
+ export default styles;
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["src"],
4
+ "exclude": ["**/*.test.snap.tsx", "**/*.test.tsx", "**/*.stories.tsx"],
5
+ "references": [{ "path": "./tsconfig.node.json" }]
6
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,83 @@
1
+ import replace from '@rollup/plugin-replace';
2
+ import copy from 'rollup-plugin-copy';
3
+ import generatePackageJson from 'rollup-plugin-generate-package-json';
4
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
5
+ import { defineConfig } from 'vite';
6
+
7
+ import { entries } from './__scripts__/entries';
8
+
9
+ const OUTPUT_DIRECTORY = 'lib';
10
+
11
+ export default defineConfig({
12
+ build: {
13
+ outDir: OUTPUT_DIRECTORY,
14
+ sourcemap: true,
15
+ lib: {
16
+ entry: 'index.js',
17
+ formats: ['es'],
18
+ },
19
+ rollupOptions: {
20
+ preserveEntrySignatures: 'strict',
21
+ input: entries,
22
+ external: [/.module.scss/],
23
+ output: {
24
+ format: 'es',
25
+ entryFileNames: '[name].js',
26
+ chunkFileNames: '[name].js',
27
+ assetFileNames: '[name].[ext]',
28
+ },
29
+ plugins: [
30
+ peerDepsExternal(),
31
+ copy({
32
+ targets: [
33
+ { src: '*.md', dest: OUTPUT_DIRECTORY },
34
+ { src: '../../CHANGELOG.md', dest: OUTPUT_DIRECTORY },
35
+ ],
36
+ hook: 'writeBundle',
37
+ }),
38
+ copy({
39
+ targets: [
40
+ { src: 'src/components/**/*.module.scss*', dest: OUTPUT_DIRECTORY },
41
+ { src: 'types/**/*.d.ts*', dest: OUTPUT_DIRECTORY },
42
+ ],
43
+ hook: 'writeBundle',
44
+ flatten: false,
45
+ }),
46
+ generatePackageJson({
47
+ baseContents: ({
48
+ name,
49
+ type,
50
+ description,
51
+ repository,
52
+ homepage,
53
+ version,
54
+ author,
55
+ license,
56
+ dependencies = {},
57
+ peerDependencies = {},
58
+ sideEffects,
59
+ }) => ({
60
+ name,
61
+ type,
62
+ description,
63
+ repository,
64
+ homepage,
65
+ version,
66
+ author,
67
+ license,
68
+ dependencies,
69
+ peerDependencies,
70
+ sideEffects,
71
+ }),
72
+ }),
73
+ // rollup har begynt å legge til ?used på slutten av styles.module.scss når vi behandler
74
+ // dem som external.
75
+ replace({
76
+ '.module.scss?used': '.module.scss',
77
+ '.module.css?used': '.module.css',
78
+ preventAssignment: true,
79
+ }),
80
+ ],
81
+ },
82
+ },
83
+ });
@@ -0,0 +1,28 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'jsdom',
7
+ setupFiles: ['../designsystem/src/utils/tests/setup-test.ts'],
8
+ css: {
9
+ modules: {
10
+ classNameStrategy: 'non-scoped',
11
+ },
12
+ },
13
+ coverage: {
14
+ enabled: true,
15
+ provider: 'istanbul',
16
+ reporter: ['cobertura', 'lcov', 'json'],
17
+ },
18
+ reporters: ['default', 'junit'],
19
+ outputFile: {
20
+ junit: 'test-report.xml',
21
+ },
22
+ server: {
23
+ deps: {
24
+ inline: ['@helsenorge/designsystem-react'],
25
+ },
26
+ },
27
+ },
28
+ });