@ndlib/component-library 0.0.7
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/components/elements/Button/Button.stories.d.ts +8 -0
- package/dist/components/elements/Button/Button.stories.js +39 -0
- package/dist/components/elements/Button/Button.test.d.ts +1 -0
- package/dist/components/elements/Button/Button.test.js +20 -0
- package/dist/components/elements/Button/index.d.ts +20 -0
- package/dist/components/elements/Button/index.js +82 -0
- package/dist/components/elements/Group/index.d.ts +23 -0
- package/dist/components/elements/Group/index.js +70 -0
- package/dist/components/elements/Link/Link.stories.d.ts +6 -0
- package/dist/components/elements/Link/Link.stories.js +21 -0
- package/dist/components/elements/Link/Link.test.d.ts +1 -0
- package/dist/components/elements/Link/Link.test.js +58 -0
- package/dist/components/elements/Link/index.d.ts +14 -0
- package/dist/components/elements/Link/index.js +41 -0
- package/dist/components/elements/layout/Box.d.ts +6 -0
- package/dist/components/elements/layout/Box.js +4 -0
- package/dist/components/elements/layout/Box.stories.d.ts +6 -0
- package/dist/components/elements/layout/Box.stories.js +12 -0
- package/dist/components/elements/layout/Column.d.ts +7 -0
- package/dist/components/elements/layout/Column.js +18 -0
- package/dist/components/elements/layout/Flex.stories.d.ts +9 -0
- package/dist/components/elements/layout/Flex.stories.js +23 -0
- package/dist/components/elements/layout/Flex.test.d.ts +1 -0
- package/dist/components/elements/layout/Flex.test.js +34 -0
- package/dist/components/elements/layout/Row.d.ts +17 -0
- package/dist/components/elements/layout/Row.js +44 -0
- package/dist/components/elements/text/Heading/Heading.stories.d.ts +8 -0
- package/dist/components/elements/text/Heading/Heading.stories.js +37 -0
- package/dist/components/elements/text/Heading/Heading.test.d.ts +1 -0
- package/dist/components/elements/text/Heading/Heading.test.js +51 -0
- package/dist/components/elements/text/Heading/index.d.ts +19 -0
- package/dist/components/elements/text/Heading/index.js +59 -0
- package/dist/components/elements/text/Label/Label.stories.d.ts +6 -0
- package/dist/components/elements/text/Label/Label.stories.js +20 -0
- package/dist/components/elements/text/Label/Label.test.d.ts +1 -0
- package/dist/components/elements/text/Label/Label.test.js +56 -0
- package/dist/components/elements/text/Label/index.d.ts +20 -0
- package/dist/components/elements/text/Label/index.js +36 -0
- package/dist/components/elements/text/Paragraph/Paragraph.stories.d.ts +6 -0
- package/dist/components/elements/text/Paragraph/Paragraph.stories.js +26 -0
- package/dist/components/elements/text/Paragraph/Paragraph.test.d.ts +1 -0
- package/dist/components/elements/text/Paragraph/Paragraph.test.js +9 -0
- package/dist/components/elements/text/Paragraph/index.d.ts +13 -0
- package/dist/components/elements/text/Paragraph/index.js +29 -0
- package/dist/components/providers/componentConfig.d.ts +20 -0
- package/dist/components/providers/componentConfig.js +31 -0
- package/dist/components/providers/env.d.ts +14 -0
- package/dist/components/providers/env.js +25 -0
- package/dist/components/providers/theme.d.ts +2 -0
- package/dist/components/providers/theme.js +6 -0
- package/dist/components/providers/ui.d.ts +10 -0
- package/dist/components/providers/ui.js +7 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/theme/Color.stories.d.ts +5 -0
- package/dist/theme/Color.stories.js +26 -0
- package/dist/theme/colors.d.ts +14 -0
- package/dist/theme/colors.js +23 -0
- package/dist/theme/index.d.ts +19 -0
- package/dist/theme/index.js +18 -0
- package/dist/theme/spacing.d.ts +0 -0
- package/dist/theme/spacing.js +1 -0
- package/dist/theme/typography.d.ts +52 -0
- package/dist/theme/typography.js +135 -0
- package/dist/utils/misc.d.ts +3 -0
- package/dist/utils/misc.js +1 -0
- package/dist/utils/test.d.ts +2 -0
- package/dist/utils/test.js +7 -0
- package/global.css +59 -0
- package/package.json +72 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { GROUP_TYPE, Group } from '../../Group';
|
|
3
|
+
import { HEADING_SIZE, Heading } from '.';
|
|
4
|
+
import { Column } from '../../layout/Column';
|
|
5
|
+
import { COLOR } from '../../../../theme/colors';
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Elements/Heading',
|
|
8
|
+
component: Heading,
|
|
9
|
+
//👇 Enables auto-generated documentation for the component story
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
const sizes = [
|
|
14
|
+
{ size: HEADING_SIZE.XL, label: 'Extra Large (Default Level 1)' },
|
|
15
|
+
{ size: HEADING_SIZE.LG, label: 'Large (Default Level 2)' },
|
|
16
|
+
{ size: HEADING_SIZE.MD, label: 'Medium (Default Level 3)' },
|
|
17
|
+
{ size: HEADING_SIZE.SM, label: 'Small (Default Level 4)' },
|
|
18
|
+
{ size: HEADING_SIZE.XS, label: 'Extra Small (Default Level 5)' },
|
|
19
|
+
];
|
|
20
|
+
export const Default = {
|
|
21
|
+
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size }, { children: size.label })) })))) })),
|
|
22
|
+
args: {
|
|
23
|
+
children: "Heading"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const Color = {
|
|
27
|
+
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size, sx: { color: COLOR.PRIMARY } }, { children: size.label })) })))) })),
|
|
28
|
+
args: {
|
|
29
|
+
children: "Heading"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const Underline = {
|
|
33
|
+
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size, underline: true }, { children: size.label })) })))) })),
|
|
34
|
+
args: {
|
|
35
|
+
children: "Heading"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { vi } from 'vitest';
|
|
12
|
+
import { render as _render } from '../../../../utils/test';
|
|
13
|
+
import { Heading } from ".";
|
|
14
|
+
import { GROUP_TYPE, Group } from '../../Group';
|
|
15
|
+
import { ENVIRONMENT } from '../../../providers/env';
|
|
16
|
+
const render = (component) => {
|
|
17
|
+
return _render(component, { env: ENVIRONMENT.DEV });
|
|
18
|
+
};
|
|
19
|
+
describe('Heading', () => {
|
|
20
|
+
const originalError = console.error;
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
console.error = vi.fn();
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
console.error = originalError;
|
|
26
|
+
vi.useRealTimers();
|
|
27
|
+
});
|
|
28
|
+
it('renders without an error if passed standalone prop', () => {
|
|
29
|
+
const { getByText } = render(_jsx(Heading, Object.assign({ standalone: true }, { children: "Foo" })));
|
|
30
|
+
expect(getByText('Foo')).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
it('renders without an error if used within region Group component', () => {
|
|
33
|
+
const { getByText } = render(_jsx(Group, { children: _jsx(Heading, { children: "Foo" }) }));
|
|
34
|
+
expect(getByText('Foo')).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
it('throws if used outside a Group component', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
expect(() => render(_jsx(Heading, { children: "Foo" }))).toThrow();
|
|
38
|
+
}));
|
|
39
|
+
it('throws if used within non-region Group component', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
expect(() => render(_jsx(Group, Object.assign({ type: GROUP_TYPE.GROUP }, { children: _jsx(Heading, { children: "Foo" }) })))).toThrow();
|
|
41
|
+
}));
|
|
42
|
+
it('labels group target automatically', () => {
|
|
43
|
+
const { getByLabelText } = render(_jsx(Group, { children: _jsx(Heading, { children: "Foo" }) }));
|
|
44
|
+
expect(getByLabelText('Foo')).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
it('is required to render region Group component', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
vi.useFakeTimers();
|
|
48
|
+
render(_jsx(Group, { children: "Foo" }));
|
|
49
|
+
expect(() => vi.runAllTimers()).toThrow();
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { StyledElementProps } from "../../../../theme";
|
|
4
|
+
import { COLOR } from "../../../../theme/colors";
|
|
5
|
+
type HeaderProps = StyledElementProps<HTMLSpanElement, {
|
|
6
|
+
size?: HEADING_SIZE;
|
|
7
|
+
standalone?: boolean;
|
|
8
|
+
underline?: boolean;
|
|
9
|
+
underlineColor?: COLOR;
|
|
10
|
+
}>;
|
|
11
|
+
export declare enum HEADING_SIZE {
|
|
12
|
+
XS = "xs",
|
|
13
|
+
SM = "sm",
|
|
14
|
+
MD = "md",
|
|
15
|
+
LG = "lg",
|
|
16
|
+
XL = "xl"
|
|
17
|
+
}
|
|
18
|
+
export declare const Heading: React.FC<HeaderProps>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
|
+
/** @jsxImportSource theme-ui */
|
|
14
|
+
import { useEffect } from "react";
|
|
15
|
+
import { getTypographyStyles, TYPOGRAPHY_TYPE } from "../../../../theme/typography";
|
|
16
|
+
import { GROUP_TYPE, useGroup } from "../../Group";
|
|
17
|
+
import { COLOR } from "../../../../theme/colors";
|
|
18
|
+
import { useEnvironment } from "../../../providers/env";
|
|
19
|
+
export var HEADING_SIZE;
|
|
20
|
+
(function (HEADING_SIZE) {
|
|
21
|
+
HEADING_SIZE["XS"] = "xs";
|
|
22
|
+
HEADING_SIZE["SM"] = "sm";
|
|
23
|
+
HEADING_SIZE["MD"] = "md";
|
|
24
|
+
HEADING_SIZE["LG"] = "lg";
|
|
25
|
+
HEADING_SIZE["XL"] = "xl";
|
|
26
|
+
})(HEADING_SIZE || (HEADING_SIZE = {}));
|
|
27
|
+
const SIZE_TYPOGRAPHY_MAP = {
|
|
28
|
+
[HEADING_SIZE.XS]: TYPOGRAPHY_TYPE.HEADING_XSMALL,
|
|
29
|
+
[HEADING_SIZE.SM]: TYPOGRAPHY_TYPE.HEADING_SMALL,
|
|
30
|
+
[HEADING_SIZE.MD]: TYPOGRAPHY_TYPE.HEADING_MEDIUM,
|
|
31
|
+
[HEADING_SIZE.LG]: TYPOGRAPHY_TYPE.HEADING_LARGE,
|
|
32
|
+
[HEADING_SIZE.XL]: TYPOGRAPHY_TYPE.HEADING_XLARGE,
|
|
33
|
+
};
|
|
34
|
+
const LEVEL_TYPOGRAPHY_MAP = {
|
|
35
|
+
1: TYPOGRAPHY_TYPE.HEADING_XLARGE,
|
|
36
|
+
2: TYPOGRAPHY_TYPE.HEADING_LARGE,
|
|
37
|
+
3: TYPOGRAPHY_TYPE.HEADING_MEDIUM,
|
|
38
|
+
4: TYPOGRAPHY_TYPE.HEADING_SMALL,
|
|
39
|
+
5: TYPOGRAPHY_TYPE.HEADING_XSMALL,
|
|
40
|
+
};
|
|
41
|
+
export const Heading = (_a) => {
|
|
42
|
+
var { sx, size, standalone, underline, underlineColor } = _a, rest = __rest(_a, ["sx", "size", "standalone", "underline", "underlineColor"]);
|
|
43
|
+
const { level, labelId, type, trackHeadingRendered } = useGroup();
|
|
44
|
+
const { flagInDevelopment } = useEnvironment();
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
trackHeadingRendered();
|
|
47
|
+
});
|
|
48
|
+
let typography = TYPOGRAPHY_TYPE.HEADING_MEDIUM;
|
|
49
|
+
if (size) {
|
|
50
|
+
typography = SIZE_TYPOGRAPHY_MAP[size];
|
|
51
|
+
}
|
|
52
|
+
else if (level) {
|
|
53
|
+
typography = LEVEL_TYPOGRAPHY_MAP[level];
|
|
54
|
+
}
|
|
55
|
+
if (type !== GROUP_TYPE.REGION && !standalone) {
|
|
56
|
+
flagInDevelopment('Heading component should be used within a Group component with property type={GROUP_TYPE.REGION} or given the standalone flag');
|
|
57
|
+
}
|
|
58
|
+
return (_jsx("div", Object.assign({ id: labelId, role: "heading", "aria-level": level, sx: Object.assign(Object.assign({ py: 0, borderBottom: underline ? 'solid 2px' : undefined, borderBottomColor: underlineColor ? underlineColor : COLOR.SECONDARY }, getTypographyStyles(typography)), sx) }, rest)));
|
|
59
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { GROUP_TYPE, Group } from '../../Group';
|
|
3
|
+
import { LABEL_SIZE, Label } from '.';
|
|
4
|
+
import { Column } from '../../layout/Column';
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Elements/Label',
|
|
7
|
+
component: Label,
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
const sizes = [
|
|
11
|
+
{ size: LABEL_SIZE.LG, label: 'Large' },
|
|
12
|
+
{ size: LABEL_SIZE.MD, label: 'Medium' },
|
|
13
|
+
{ size: LABEL_SIZE.SM, label: 'Small' },
|
|
14
|
+
];
|
|
15
|
+
export const Default = {
|
|
16
|
+
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.GROUP }, { children: _jsx(Label, Object.assign({ size: size.size }, { children: size.label })) })))) })),
|
|
17
|
+
args: {
|
|
18
|
+
children: "Label"
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { vi } from 'vitest';
|
|
12
|
+
import { render as _render } from '../../../../utils/test';
|
|
13
|
+
import { Label } from ".";
|
|
14
|
+
import { GROUP_TYPE, Group } from '../../Group';
|
|
15
|
+
import { ENVIRONMENT } from '../../../providers/env';
|
|
16
|
+
import userEvent from '@testing-library/user-event';
|
|
17
|
+
import { waitFor } from '@testing-library/react';
|
|
18
|
+
const render = (component) => {
|
|
19
|
+
return _render(component, { env: ENVIRONMENT.DEV });
|
|
20
|
+
};
|
|
21
|
+
describe('Label', () => {
|
|
22
|
+
const originalError = console.error;
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
console.error = vi.fn();
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
console.error = originalError;
|
|
28
|
+
vi.useRealTimers();
|
|
29
|
+
});
|
|
30
|
+
it('renders without an error if passed standalone prop', () => {
|
|
31
|
+
const { getByText } = render(_jsx(Label, Object.assign({ standalone: true }, { children: "Foo" })));
|
|
32
|
+
expect(getByText('Foo')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
it('renders without an error if used within region Group component', () => {
|
|
35
|
+
const { getByText } = render(_jsx(Group, Object.assign({ type: GROUP_TYPE.GROUP }, { children: _jsx(Label, { children: "Foo" }) })));
|
|
36
|
+
expect(getByText('Foo')).toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
it('throws if used outside a Group component', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
expect(() => render(_jsx(Label, { children: "Foo" }))).toThrow();
|
|
40
|
+
}));
|
|
41
|
+
it('throws if used within non-group-type Group component', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
expect(() => render(_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Label, { children: "Foo" }) })))).toThrow();
|
|
43
|
+
}));
|
|
44
|
+
it('labels group target automatically', () => {
|
|
45
|
+
const { getByLabelText } = render(_jsx(Group, Object.assign({ type: GROUP_TYPE.GROUP }, { children: _jsx(Label, { children: "Foo" }) })));
|
|
46
|
+
expect(getByLabelText('Foo')).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
it('can send focus to label target', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const INPUT_TEST_ID = 'input-test-id';
|
|
50
|
+
const { getByText, getByTestId } = render((_jsx(Group, Object.assign({ type: GROUP_TYPE.GROUP }, { children: ({ labelTargetId }) => (_jsxs(_Fragment, { children: [_jsx(Label, { children: "Foo" }), _jsx("input", { id: labelTargetId, "data-testid": INPUT_TEST_ID })] })) }))));
|
|
51
|
+
userEvent.click(getByText('Foo'));
|
|
52
|
+
yield waitFor(() => {
|
|
53
|
+
expect(getByTestId(INPUT_TEST_ID)).toHaveFocus();
|
|
54
|
+
});
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { TYPOGRAPHY_TYPE } from "../../../../theme/typography";
|
|
4
|
+
import { StyledElementProps } from "../../../../theme";
|
|
5
|
+
export declare enum LABEL_SIZE {
|
|
6
|
+
SM = "sm",
|
|
7
|
+
MD = "md",
|
|
8
|
+
LG = "lg"
|
|
9
|
+
}
|
|
10
|
+
export declare const SIZE_TYPOGRAPHY_MAP: {
|
|
11
|
+
sm: TYPOGRAPHY_TYPE;
|
|
12
|
+
md: TYPOGRAPHY_TYPE;
|
|
13
|
+
lg: TYPOGRAPHY_TYPE;
|
|
14
|
+
};
|
|
15
|
+
type LabelProps = StyledElementProps<HTMLLabelElement, {
|
|
16
|
+
size?: LABEL_SIZE;
|
|
17
|
+
standalone?: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const Label: React.FC<LabelProps>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
|
+
import { getTypographyStyles, TYPOGRAPHY_TYPE } from "../../../../theme/typography";
|
|
14
|
+
import { GROUP_TYPE, useGroup } from "../../Group";
|
|
15
|
+
import { useEnvironment } from "../../../providers/env";
|
|
16
|
+
export var LABEL_SIZE;
|
|
17
|
+
(function (LABEL_SIZE) {
|
|
18
|
+
LABEL_SIZE["SM"] = "sm";
|
|
19
|
+
LABEL_SIZE["MD"] = "md";
|
|
20
|
+
LABEL_SIZE["LG"] = "lg";
|
|
21
|
+
})(LABEL_SIZE || (LABEL_SIZE = {}));
|
|
22
|
+
export const SIZE_TYPOGRAPHY_MAP = {
|
|
23
|
+
[LABEL_SIZE.SM]: TYPOGRAPHY_TYPE.CONTROL_SMALL,
|
|
24
|
+
[LABEL_SIZE.MD]: TYPOGRAPHY_TYPE.CONTROL_MEDIUM,
|
|
25
|
+
[LABEL_SIZE.LG]: TYPOGRAPHY_TYPE.CONTROL_LARGE
|
|
26
|
+
};
|
|
27
|
+
export const Label = (_a) => {
|
|
28
|
+
var { sx, size, standalone } = _a, rest = __rest(_a, ["sx", "size", "standalone"]);
|
|
29
|
+
const { labelId, labelTargetId, type: groupType } = useGroup();
|
|
30
|
+
const { flagInDevelopment } = useEnvironment();
|
|
31
|
+
const typography = SIZE_TYPOGRAPHY_MAP[size || LABEL_SIZE.MD];
|
|
32
|
+
if (groupType !== GROUP_TYPE.GROUP && !standalone) {
|
|
33
|
+
flagInDevelopment('Label component should be used within a Group component with property type={GROUP_TYPE.GROUP} or given the standalone flag');
|
|
34
|
+
}
|
|
35
|
+
return (_jsx("label", Object.assign({ id: labelId, htmlFor: labelTargetId, sx: Object.assign(Object.assign({}, getTypographyStyles(typography)), sx) }, rest)));
|
|
36
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { GROUP_TYPE, Group } from '../../Group';
|
|
3
|
+
import { PARAGRAPH_SIZE, Paragraph } from '.';
|
|
4
|
+
import { Column } from '../../layout/Column';
|
|
5
|
+
import { HEADING_SIZE, Heading } from '../Heading';
|
|
6
|
+
import { COLOR } from '../../../../theme/colors';
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Elements/Paragraph',
|
|
9
|
+
component: Paragraph,
|
|
10
|
+
//👇 Enables auto-generated documentation for the component story
|
|
11
|
+
tags: ['autodocs'],
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
const sizes = [
|
|
15
|
+
{ size: PARAGRAPH_SIZE.LG, label: 'Large' },
|
|
16
|
+
{ size: PARAGRAPH_SIZE.MD, label: 'Medium' },
|
|
17
|
+
{ size: PARAGRAPH_SIZE.SM, label: 'Small' },
|
|
18
|
+
];
|
|
19
|
+
const p1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ultrices venenatis purus at porta. Etiam congue sapien leo, sed malesuada justo commodo in. Nunc consequat, massa non cursus posuere, magna eros lacinia lectus, eget lobortis mi erat ut justo. Maecenas nisi mi, mollis sed ornare vitae, pharetra sed augue. Curabitur mollis orci risus, sed imperdiet nisi aliquet et. Ut non elit nec magna rhoncus maximus sit amet ut dui. Mauris sit amet eleifend lectus. Aliquam consectetur posuere libero eu ultricies. Etiam rutrum non orci nec vulputate. Sed vel accumsan diam. Cras aliquet eros eros, sit amet pharetra eros tincidunt ut. Vestibulum est erat, eleifend dapibus eros vel, elementum vehicula risus. Etiam blandit condimentum sodales. Donec non libero in orci aliquam egestas fringilla eget purus. Suspendisse pellentesque at ligula ut accumsan.';
|
|
20
|
+
const p2 = 'Sed non lobortis mi, vitae dapibus arcu. Aenean at euismod arcu. Ut consectetur porttitor mattis. In eget vehicula augue. Ut at dolor posuere, tristique nisi finibus, posuere turpis. Etiam placerat, dui id lacinia volutpat, lorem turpis volutpat nisi, vel dapibus purus lorem at ante. Ut imperdiet enim nec arcu sagittis luctus.';
|
|
21
|
+
export const Default = {
|
|
22
|
+
render: (args) => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG, underline: true, sx: { color: COLOR.PRIMARY } }, { children: size.label })), [p1, p2].map((content) => (_jsx(Paragraph, Object.assign({}, args, { size: size.size }, { children: content }))))] })))) })),
|
|
23
|
+
args: {
|
|
24
|
+
children: "Heading"
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '../../../../utils/test';
|
|
3
|
+
import { Paragraph } from ".";
|
|
4
|
+
describe('Paragraph', () => {
|
|
5
|
+
it('renders without an error', () => {
|
|
6
|
+
const { getByText } = render(_jsx(Paragraph, { children: "Foo" }));
|
|
7
|
+
expect(getByText('Foo')).toBeInTheDocument();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { StyledElementProps } from "../../../../theme";
|
|
4
|
+
type ParagraphProps = StyledElementProps<HTMLSpanElement, {
|
|
5
|
+
size?: PARAGRAPH_SIZE;
|
|
6
|
+
}>;
|
|
7
|
+
export declare enum PARAGRAPH_SIZE {
|
|
8
|
+
SM = "sm",
|
|
9
|
+
MD = "md",
|
|
10
|
+
LG = "lg"
|
|
11
|
+
}
|
|
12
|
+
export declare const Paragraph: React.FC<ParagraphProps>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
|
+
import { getTypographyStyles, TYPOGRAPHY_TYPE } from "../../../../theme/typography";
|
|
14
|
+
export var PARAGRAPH_SIZE;
|
|
15
|
+
(function (PARAGRAPH_SIZE) {
|
|
16
|
+
PARAGRAPH_SIZE["SM"] = "sm";
|
|
17
|
+
PARAGRAPH_SIZE["MD"] = "md";
|
|
18
|
+
PARAGRAPH_SIZE["LG"] = "lg";
|
|
19
|
+
})(PARAGRAPH_SIZE || (PARAGRAPH_SIZE = {}));
|
|
20
|
+
const SIZE_TYPOGRAPHY_MAP = {
|
|
21
|
+
[PARAGRAPH_SIZE.SM]: TYPOGRAPHY_TYPE.PARAGRAPH_SMALL,
|
|
22
|
+
[PARAGRAPH_SIZE.MD]: TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM,
|
|
23
|
+
[PARAGRAPH_SIZE.LG]: TYPOGRAPHY_TYPE.PARAGRAPH_LARGE
|
|
24
|
+
};
|
|
25
|
+
export const Paragraph = (_a) => {
|
|
26
|
+
var { size, sx } = _a, rest = __rest(_a, ["size", "sx"]);
|
|
27
|
+
const typography = SIZE_TYPOGRAPHY_MAP[size || PARAGRAPH_SIZE.MD];
|
|
28
|
+
return (_jsx("div", Object.assign({ sx: Object.assign(Object.assign(Object.assign({}, getTypographyStyles(typography)), { my: 1 }), sx) }, rest)));
|
|
29
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { DeepPartial } from "../../utils/misc";
|
|
3
|
+
import { StyledElementProps } from "../../theme";
|
|
4
|
+
export type ComponentConfig = {
|
|
5
|
+
link: {
|
|
6
|
+
externalMatcher: RegExp;
|
|
7
|
+
internalLinkComponent: React.FC<LinkComponentProps>;
|
|
8
|
+
externalLinkComponent: React.FC<LinkComponentProps>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type ComponentConfigParam = DeepPartial<ComponentConfig>;
|
|
12
|
+
export type LinkComponentProps = StyledElementProps<HTMLAnchorElement, {
|
|
13
|
+
to: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const DefaultLink: React.FC<LinkComponentProps>;
|
|
16
|
+
export declare const ComponentConfigContext: import("react").Context<ComponentConfig>;
|
|
17
|
+
export declare const useComponentConfig: () => ComponentConfig;
|
|
18
|
+
export declare const ComponentConfigProvider: React.FC<PropsWithChildren<{
|
|
19
|
+
config: ComponentConfigParam;
|
|
20
|
+
}>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useMemo } from "react";
|
|
14
|
+
const DEFAULT_EXTERNAL_LINK_MATCHER = /[a-zA-Z0-9]*:\/\/[^\s]*/g;
|
|
15
|
+
export const DefaultLink = (_a) => {
|
|
16
|
+
var { to } = _a, rest = __rest(_a, ["to"]);
|
|
17
|
+
return _jsx("a", Object.assign({ href: to }, rest));
|
|
18
|
+
};
|
|
19
|
+
const defaultComponentConfig = {
|
|
20
|
+
link: {
|
|
21
|
+
externalMatcher: DEFAULT_EXTERNAL_LINK_MATCHER,
|
|
22
|
+
internalLinkComponent: DefaultLink,
|
|
23
|
+
externalLinkComponent: DefaultLink
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const ComponentConfigContext = createContext(defaultComponentConfig);
|
|
27
|
+
export const useComponentConfig = () => useContext(ComponentConfigContext);
|
|
28
|
+
export const ComponentConfigProvider = ({ config: configParam, children }) => {
|
|
29
|
+
const config = useMemo(() => (Object.assign(Object.assign(Object.assign({}, defaultComponentConfig), configParam), { link: Object.assign(Object.assign({}, defaultComponentConfig.link), configParam.link) })), []); // eslint-disable-line
|
|
30
|
+
return (_jsx(ComponentConfigContext.Provider, Object.assign({ value: config }, { children: children })));
|
|
31
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
export declare enum ENVIRONMENT {
|
|
3
|
+
DEV = "DEVELOPMENT",
|
|
4
|
+
PROD = "PRODUCTION"
|
|
5
|
+
}
|
|
6
|
+
type EnvironmentContextType = {
|
|
7
|
+
env?: ENVIRONMENT;
|
|
8
|
+
flagInDevelopment: (message: string) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const useEnvironment: () => EnvironmentContextType;
|
|
11
|
+
export declare const EnvironmentProvider: React.FC<PropsWithChildren<{
|
|
12
|
+
env?: ENVIRONMENT;
|
|
13
|
+
}>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export var ENVIRONMENT;
|
|
4
|
+
(function (ENVIRONMENT) {
|
|
5
|
+
ENVIRONMENT["DEV"] = "DEVELOPMENT";
|
|
6
|
+
ENVIRONMENT["PROD"] = "PRODUCTION";
|
|
7
|
+
})(ENVIRONMENT || (ENVIRONMENT = {}));
|
|
8
|
+
const EnvironmentContext = createContext({
|
|
9
|
+
flagInDevelopment: () => { }
|
|
10
|
+
});
|
|
11
|
+
export const useEnvironment = () => useContext(EnvironmentContext);
|
|
12
|
+
export const EnvironmentProvider = ({ env, children }) => {
|
|
13
|
+
const flagInDevelopment = (message) => {
|
|
14
|
+
if (env === ENVIRONMENT.DEV) {
|
|
15
|
+
throw new Error(message);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.warn(message);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return (_jsx(EnvironmentContext.Provider, Object.assign({ value: {
|
|
22
|
+
env,
|
|
23
|
+
flagInDevelopment
|
|
24
|
+
} }, { children: children })));
|
|
25
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeProvider as ThemeUiProvider } from 'theme-ui';
|
|
3
|
+
import { theme } from '../../theme';
|
|
4
|
+
export const ThemeProvider = ({ children }) => {
|
|
5
|
+
return (_jsx(ThemeUiProvider, Object.assign({ theme: theme }, { children: children })));
|
|
6
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { ComponentConfigParam } from "./componentConfig";
|
|
3
|
+
import { ENVIRONMENT } from "./env";
|
|
4
|
+
export type UiConfig = {
|
|
5
|
+
env?: ENVIRONMENT;
|
|
6
|
+
components?: ComponentConfigParam;
|
|
7
|
+
};
|
|
8
|
+
type UiProviderProps = PropsWithChildren<UiConfig>;
|
|
9
|
+
export declare const UiProvider: React.FC<UiProviderProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ComponentConfigProvider } from "./componentConfig";
|
|
3
|
+
import { EnvironmentProvider } from "./env";
|
|
4
|
+
import { ThemeProvider } from "./theme";
|
|
5
|
+
export const UiProvider = ({ env, components, children }) => {
|
|
6
|
+
return (_jsx(EnvironmentProvider, Object.assign({ env: env }, { children: _jsx(ComponentConfigProvider, Object.assign({ config: components || {} }, { children: _jsx(ThemeProvider, { children: children }) })) })));
|
|
7
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { theme, ThemeProvider } from './theme';
|
|
2
|
+
export { COLOR } from './theme/colors';
|
|
3
|
+
export { TYPOGRAPHY_TYPE } from './theme/typography';
|
|
4
|
+
export { Button, BUTTON_SIZE } from './components/elements/Button';
|
|
5
|
+
export { Heading, HEADING_SIZE } from './components/elements/text/Heading';
|
|
6
|
+
export { Label, LABEL_SIZE } from './components/elements/text/Label';
|
|
7
|
+
export { Paragraph, PARAGRAPH_SIZE } from './components/elements/text/Paragraph';
|
|
8
|
+
export { Group, useGroup } from './components/elements/Group';
|
|
9
|
+
export { Box } from './components/elements/layout/Box';
|
|
10
|
+
export { Column } from './components/elements/layout/Column';
|
|
11
|
+
export { Row } from './components/elements/layout/Row';
|
|
12
|
+
export { Link, LINK_SIZE } from './components/elements/Link';
|
|
13
|
+
export { UiProvider } from './components/providers/ui';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { theme, ThemeProvider } from './theme';
|
|
2
|
+
export { COLOR } from './theme/colors';
|
|
3
|
+
export { TYPOGRAPHY_TYPE } from './theme/typography';
|
|
4
|
+
export { Button, BUTTON_SIZE } from './components/elements/Button';
|
|
5
|
+
export { Heading, HEADING_SIZE } from './components/elements/text/Heading';
|
|
6
|
+
export { Label, LABEL_SIZE } from './components/elements/text/Label';
|
|
7
|
+
export { Paragraph, PARAGRAPH_SIZE } from './components/elements/text/Paragraph';
|
|
8
|
+
export { Group, useGroup } from './components/elements/Group';
|
|
9
|
+
export { Box } from './components/elements/layout/Box';
|
|
10
|
+
export { Column } from './components/elements/layout/Column';
|
|
11
|
+
export { Row } from './components/elements/layout/Row';
|
|
12
|
+
export { Link, LINK_SIZE } from './components/elements/Link';
|
|
13
|
+
export { UiProvider } from './components/providers/ui';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { COLOR } from './colors';
|
|
3
|
+
import { GROUP_TYPE, Group } from '../components/elements/Group';
|
|
4
|
+
import { Row } from '../components/elements/layout/Row';
|
|
5
|
+
import { Box } from '../components/elements/layout/Box';
|
|
6
|
+
import { LABEL_SIZE, Label } from '../components/elements/text/Label';
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Theme/Colors',
|
|
9
|
+
};
|
|
10
|
+
const ColorSquare = ({ color }) => {
|
|
11
|
+
return _jsx(Box, { sx: { p: 3, bg: color, boxShadow: '0px 0px 8px 1px #dddddd' } });
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
const colors = [
|
|
15
|
+
{ color: COLOR.TEXT, label: 'TEXT' },
|
|
16
|
+
{ color: COLOR.BACKGROUND, label: 'BACKGROUND' },
|
|
17
|
+
{ color: COLOR.PRIMARY, label: 'PRIMARY' },
|
|
18
|
+
{ color: COLOR.PRIMARY_HIGHLIGHT, label: 'PRIMARY_HIGHLIGHT' },
|
|
19
|
+
{ color: COLOR.TEXT_ON_PRIMARY, label: 'TEXT_ON_PRIMARY' },
|
|
20
|
+
{ color: COLOR.SECONDARY, label: 'SECONDARY' },
|
|
21
|
+
{ color: COLOR.SECONDARY_HIGHLIGHT, label: 'SECONDARY_HIGHLIGHT' },
|
|
22
|
+
{ color: COLOR.TEXT_ON_SECONDARY, label: 'TEXT_ON_SECONDARY' },
|
|
23
|
+
];
|
|
24
|
+
export const Default = {
|
|
25
|
+
render: () => (_jsx(Row, Object.assign({ sx: { flexWrap: 'wrap' } }, { children: colors.map((color) => (_jsxs(Group, Object.assign({ type: GROUP_TYPE.GROUP, sx: { mr: 3, mt: 0, flexBasis: '100px' } }, { children: [_jsx(Label, Object.assign({ size: LABEL_SIZE.SM }, { children: color.label })), _jsx(ColorSquare, { color: color.color })] })))) }))),
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum COLOR {
|
|
2
|
+
TEXT = "text",
|
|
3
|
+
BACKGROUND = "background",
|
|
4
|
+
TRANSPARENT = "transparent",
|
|
5
|
+
PRIMARY = "primary",
|
|
6
|
+
PRIMARY_HIGHLIGHT = "primaryHighlight",
|
|
7
|
+
SECONDARY = "secondary",
|
|
8
|
+
SECONDARY_HIGHLIGHT = "secondaryHighlight",
|
|
9
|
+
TEXT_ON_PRIMARY = "textOnPrimary",
|
|
10
|
+
TEXT_ON_SECONDARY = "textOnSecondary"
|
|
11
|
+
}
|
|
12
|
+
export declare const colors: {
|
|
13
|
+
[key in COLOR]: string;
|
|
14
|
+
};
|