@momentum-design/components 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +16 -0
- package/CONTRIBUTING.md +5 -0
- package/README.md +39 -0
- package/SCRIPTS.md +15 -0
- package/TESTING.md +38 -0
- package/config/api-extractor.json +33 -0
- package/config/custom-elements-manifest.config.js +28 -0
- package/config/esbuild/configs/browser.js +21 -0
- package/config/esbuild/configs/e2e.js +10 -0
- package/config/esbuild/esbuild-e2e.config.js +22 -0
- package/config/esbuild/esbuild.config.js +9 -0
- package/config/playwright/playwright.config.ts +107 -0
- package/config/playwright/public/index.css +43 -0
- package/config/playwright/public/index.html +26 -0
- package/config/playwright/setup/Components.page.ts +163 -0
- package/config/playwright/setup/constants.ts +27 -0
- package/config/playwright/setup/index.ts +42 -0
- package/config/playwright/setup/steps/accessibility.ts +9 -0
- package/config/playwright/setup/types.ts +5 -0
- package/config/playwright/setup/utils/accessibility.ts +70 -0
- package/config/playwright/setup/utils/visual-regression.ts +35 -0
- package/config/plop/actions/AddComponent.ts +21 -0
- package/config/plop/actions/AddToComponentExports.ts +16 -0
- package/config/plop/actions/AddToComponentImports.ts +16 -0
- package/config/plop/constants/index.ts +31 -0
- package/config/plop/esbuild.config.plop.js +4 -0
- package/config/plop/generators/component/index.ts +25 -0
- package/config/plop/plopfile.ts +6 -0
- package/config/plop/prompts/index.ts +8 -0
- package/config/plop/templates/add/component/index.ts.hbs +12 -0
- package/config/plop/templates/add/component/{{componentName}}.component.ts.hbs +22 -0
- package/config/plop/templates/add/component/{{componentName}}.constants.ts.hbs +5 -0
- package/config/plop/templates/add/component/{{componentName}}.e2e-test.ts.hbs +67 -0
- package/config/plop/templates/add/component/{{componentName}}.fixtures.ts.hbs +13 -0
- package/config/plop/templates/add/component/{{componentName}}.stories.ts.hbs +18 -0
- package/config/plop/templates/add/component/{{componentName}}.styles.ts.hbs +8 -0
- package/config/plop/tsconfig.plop.json +11 -0
- package/config/storybook/MomentumStorybookTheme.js +41 -0
- package/config/storybook/main.js +21 -0
- package/config/storybook/manager.js +17 -0
- package/config/storybook/preview.js +63 -0
- package/config/storybook/provider/iconProvider.js +8 -0
- package/config/storybook/provider/themeProvider.js +31 -0
- package/config/storybook/public/background-graphic.png +0 -0
- package/config/storybook/public/fonts/Inter.var.woff2 +0 -0
- package/config/storybook/public/momentum-logo.png +0 -0
- package/config/storybook/themes/index.js +14 -0
- package/config/storybook/themes/themes.css +15 -0
- package/data/custom-elements.json +677 -0
- package/dist/browser/index.js +366 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/components/avatar/avatar.component.d.ts +28 -0
- package/dist/components/avatar/avatar.component.js +79 -0
- package/dist/components/avatar/avatar.constants.d.ts +7 -0
- package/dist/components/avatar/avatar.constants.js +14 -0
- package/dist/components/avatar/avatar.styles.d.ts +2 -0
- package/dist/components/avatar/avatar.styles.js +20 -0
- package/dist/components/avatar/avatar.types.d.ts +1 -0
- package/dist/components/avatar/avatar.types.js +2 -0
- package/dist/components/avatar/index.d.ts +7 -0
- package/dist/components/avatar/index.js +7 -0
- package/dist/components/badge/badge.component.d.ts +51 -0
- package/dist/components/badge/badge.component.js +114 -0
- package/dist/components/badge/badge.constants.d.ts +8 -0
- package/dist/components/badge/badge.constants.js +15 -0
- package/dist/components/badge/badge.styles.d.ts +2 -0
- package/dist/components/badge/badge.styles.js +26 -0
- package/dist/components/badge/badge.types.d.ts +1 -0
- package/dist/components/badge/badge.types.js +2 -0
- package/dist/components/badge/index.d.ts +7 -0
- package/dist/components/badge/index.js +7 -0
- package/dist/components/icon/icon.component.d.ts +63 -0
- package/dist/components/icon/icon.component.js +158 -0
- package/dist/components/icon/icon.constants.d.ts +6 -0
- package/dist/components/icon/icon.constants.js +12 -0
- package/dist/components/icon/icon.styles.d.ts +2 -0
- package/dist/components/icon/icon.styles.js +15 -0
- package/dist/components/icon/icon.utils.d.ts +2 -0
- package/dist/components/icon/icon.utils.js +13 -0
- package/dist/components/icon/index.d.ts +7 -0
- package/dist/components/icon/index.js +7 -0
- package/dist/components/iconprovider/iconprovider.component.d.ts +34 -0
- package/dist/components/iconprovider/iconprovider.component.js +71 -0
- package/dist/components/iconprovider/iconprovider.constants.d.ts +7 -0
- package/dist/components/iconprovider/iconprovider.constants.js +14 -0
- package/dist/components/iconprovider/iconprovider.context.d.ts +9 -0
- package/dist/components/iconprovider/iconprovider.context.js +9 -0
- package/dist/components/iconprovider/index.d.ts +7 -0
- package/dist/components/iconprovider/index.js +7 -0
- package/dist/components/text/fonts.styles.d.ts +1 -0
- package/dist/components/text/fonts.styles.js +100 -0
- package/dist/components/text/index.d.ts +7 -0
- package/dist/components/text/index.js +7 -0
- package/dist/components/text/text.component.d.ts +29 -0
- package/dist/components/text/text.component.js +41 -0
- package/dist/components/text/text.constants.d.ts +9 -0
- package/dist/components/text/text.constants.js +28 -0
- package/dist/components/text/text.styles.d.ts +2 -0
- package/dist/components/text/text.styles.js +17 -0
- package/dist/components/text/text.types.d.ts +1 -0
- package/dist/components/text/text.types.js +2 -0
- package/dist/components/text/text.utils.d.ts +20 -0
- package/dist/components/text/text.utils.js +50 -0
- package/dist/components/themeprovider/index.d.ts +7 -0
- package/dist/components/themeprovider/index.js +7 -0
- package/dist/components/themeprovider/themeprovider.component.d.ts +48 -0
- package/dist/components/themeprovider/themeprovider.component.js +86 -0
- package/dist/components/themeprovider/themeprovider.constants.d.ts +10 -0
- package/dist/components/themeprovider/themeprovider.constants.js +31 -0
- package/dist/components/themeprovider/themeprovider.context.d.ts +9 -0
- package/dist/components/themeprovider/themeprovider.context.js +13 -0
- package/dist/components/themeprovider/themeprovider.styles.d.ts +2 -0
- package/dist/components/themeprovider/themeprovider.styles.js +13 -0
- package/dist/components/themeprovider/themeprovider.types.d.ts +5 -0
- package/dist/components/themeprovider/themeprovider.types.js +2 -0
- package/dist/components/themeprovider/themeprovider.utils.d.ts +9 -0
- package/dist/components/themeprovider/themeprovider.utils.js +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +19 -0
- package/dist/models/component/component.component.d.ts +38 -0
- package/dist/models/component/component.component.js +45 -0
- package/dist/models/component/component.types.d.ts +15 -0
- package/dist/models/component/component.types.js +2 -0
- package/dist/models/component/index.d.ts +3 -0
- package/dist/models/component/index.js +5 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +8 -0
- package/dist/models/provider/index.d.ts +2 -0
- package/dist/models/provider/index.js +5 -0
- package/dist/models/provider/provider.component.d.ts +70 -0
- package/dist/models/provider/provider.component.js +56 -0
- package/dist/models/provider/provider.styles.d.ts +2 -0
- package/dist/models/provider/provider.styles.js +14 -0
- package/dist/utils/provider/index.d.ts +13 -0
- package/dist/utils/provider/index.js +14 -0
- package/dist/utils/styles/index.d.ts +2 -0
- package/dist/utils/styles/index.js +14 -0
- package/dist/utils/tag-name/constants.d.ts +7 -0
- package/dist/utils/tag-name/constants.js +10 -0
- package/dist/utils/tag-name/index.d.ts +4 -0
- package/dist/utils/tag-name/index.js +10 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.js +2 -0
- package/jest.config.js +3 -0
- package/package.json +78 -0
- package/scripts/copyFonts.js +31 -0
- package/scripts/copyIcons.js +31 -0
- package/scripts/copyTokens.js +24 -0
- package/src/components/avatar/__screenshots__/mdc-avatar.png +0 -0
- package/src/components/avatar/avatar.component.ts +74 -0
- package/src/components/avatar/avatar.constants.ts +12 -0
- package/src/components/avatar/avatar.e2e-test.ts +70 -0
- package/src/components/avatar/avatar.stories.ts +25 -0
- package/src/components/avatar/avatar.styles.ts +20 -0
- package/src/components/avatar/avatar.types.ts +1 -0
- package/src/components/avatar/index.ts +12 -0
- package/src/components/badge/__screenshots__/mdc-badge.png +0 -0
- package/src/components/badge/badge.component.ts +121 -0
- package/src/components/badge/badge.constants.ts +13 -0
- package/src/components/badge/badge.e2e-test.ts +68 -0
- package/src/components/badge/badge.stories.ts +33 -0
- package/src/components/badge/badge.styles.ts +26 -0
- package/src/components/badge/badge.types.ts +1 -0
- package/src/components/badge/index.ts +12 -0
- package/src/components/icon/__screenshots__/mdc-icon-default.png +0 -0
- package/src/components/icon/__screenshots__/mdc-icon-scale.png +0 -0
- package/src/components/icon/icon.component.ts +155 -0
- package/src/components/icon/icon.constants.ts +10 -0
- package/src/components/icon/icon.e2e-test.ts +101 -0
- package/src/components/icon/icon.stories.ts +34 -0
- package/src/components/icon/icon.styles.ts +15 -0
- package/src/components/icon/icon.utils.ts +13 -0
- package/src/components/icon/index.ts +12 -0
- package/src/components/iconprovider/__screenshots__/mdc-iconprovider.png +0 -0
- package/src/components/iconprovider/iconprovider.component.ts +76 -0
- package/src/components/iconprovider/iconprovider.constants.ts +12 -0
- package/src/components/iconprovider/iconprovider.context.ts +16 -0
- package/src/components/iconprovider/iconprovider.e2e-test.ts +65 -0
- package/src/components/iconprovider/iconprovider.stories.ts +27 -0
- package/src/components/iconprovider/iconprovider.stories.utils.ts +27 -0
- package/src/components/iconprovider/index.ts +12 -0
- package/src/components/text/__screenshots__/mdc-text-body-large.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-body-regular.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-body-small.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-1.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-2.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-3.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-4.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-5.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-6.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-7.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-image-title.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-label.png +0 -0
- package/src/components/text/fonts.styles.ts +99 -0
- package/src/components/text/index.ts +12 -0
- package/src/components/text/text.component.ts +51 -0
- package/src/components/text/text.constants.ts +27 -0
- package/src/components/text/text.e2e-test.ts +76 -0
- package/src/components/text/text.stories.ts +29 -0
- package/src/components/text/text.styles.ts +17 -0
- package/src/components/text/text.types.ts +13 -0
- package/src/components/text/text.utils.ts +51 -0
- package/src/components/themeprovider/__screenshots__/mdc-themeprovider-darkWebex.png +0 -0
- package/src/components/themeprovider/__screenshots__/mdc-themeprovider-lightWebex.png +0 -0
- package/src/components/themeprovider/index.ts +12 -0
- package/src/components/themeprovider/themeprovider.component.ts +91 -0
- package/src/components/themeprovider/themeprovider.constants.ts +32 -0
- package/src/components/themeprovider/themeprovider.context.ts +18 -0
- package/src/components/themeprovider/themeprovider.e2e-test.ts +89 -0
- package/src/components/themeprovider/themeprovider.stories.styles.css +22 -0
- package/src/components/themeprovider/themeprovider.stories.ts +38 -0
- package/src/components/themeprovider/themeprovider.stories.utils.ts +23 -0
- package/src/components/themeprovider/themeprovider.styles.ts +13 -0
- package/src/components/themeprovider/themeprovider.types.ts +7 -0
- package/src/components/themeprovider/themeprovider.utils.ts +16 -0
- package/src/index.ts +22 -0
- package/src/models/component/component.component.ts +46 -0
- package/src/models/component/component.types.ts +16 -0
- package/src/models/component/index.ts +7 -0
- package/src/models/index.ts +11 -0
- package/src/models/provider/index.ts +3 -0
- package/src/models/provider/provider.component.ts +87 -0
- package/src/models/provider/provider.styles.ts +14 -0
- package/src/stories/colors.mdx +32 -0
- package/src/stories/icons.mdx +13 -0
- package/src/stories/typography.mdx +20 -0
- package/src/utils/mixins/DisabledMixin.ts +19 -0
- package/src/utils/mixins/TabIndexMixin.ts +19 -0
- package/src/utils/provider/index.ts +21 -0
- package/src/utils/styles/index.ts +13 -0
- package/src/utils/tag-name/constants.ts +10 -0
- package/src/utils/tag-name/index.ts +15 -0
- package/src/utils/types.ts +1 -0
- package/tsconfig.json +45 -0
- package/tsconfig.module.json +47 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
import type { Meta, StoryObj, Args } from '@storybook/web-components';
|
2
|
+
import { html } from 'lit';
|
3
|
+
import '.';
|
4
|
+
import './themeprovider.stories.styles.css';
|
5
|
+
import { THEMES } from './themeprovider.constants';
|
6
|
+
import './themeprovider.stories.utils';
|
7
|
+
|
8
|
+
const render = (args: Args) => html`
|
9
|
+
<mdc-themeprovider class="themeWrapper" theme="${args.theme}">
|
10
|
+
<p>Current theme:</p>
|
11
|
+
<mdc-subcomponent></mdc-subcomponent>
|
12
|
+
<div>
|
13
|
+
<div class="colorBox" style="background: var(--mds-color-theme-text-accent-normal);"></div>
|
14
|
+
<div class="colorBox" style="background: var(--mds-color-theme-text-warning-normal);"></div>
|
15
|
+
<div class="colorBox" style="background: var(--mds-color-theme-background-alert-success-normal);"></div>
|
16
|
+
</div>
|
17
|
+
</mdc-themeprovider>
|
18
|
+
`;
|
19
|
+
|
20
|
+
const meta: Meta = {
|
21
|
+
tags: ['autodocs'],
|
22
|
+
component: 'mdc-themeprovider',
|
23
|
+
render,
|
24
|
+
argTypes: {
|
25
|
+
theme: {
|
26
|
+
options: THEMES,
|
27
|
+
control: { type: 'radio' },
|
28
|
+
},
|
29
|
+
},
|
30
|
+
};
|
31
|
+
|
32
|
+
export default meta;
|
33
|
+
|
34
|
+
export const Primary: StoryObj = {
|
35
|
+
args: {
|
36
|
+
theme: THEMES[0],
|
37
|
+
},
|
38
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { html } from 'lit';
|
2
|
+
import { Component } from '../../models';
|
3
|
+
import ThemeProvider from './themeprovider.component';
|
4
|
+
import providerUtils from '../../utils/provider';
|
5
|
+
|
6
|
+
// Subcomponent to be rendered in storybook, to showcase that the
|
7
|
+
// theme can be consumed as a subcomponent
|
8
|
+
class SubComponentThemeProvider extends Component {
|
9
|
+
currentTheme?: string;
|
10
|
+
|
11
|
+
private themeProviderContext = providerUtils.consume({ host: this, context: ThemeProvider.Context });
|
12
|
+
|
13
|
+
override render() {
|
14
|
+
return html` <p>${this.themeProviderContext.value?.theme}</p> `;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
SubComponentThemeProvider.register('mdc-subcomponent');
|
19
|
+
declare global {
|
20
|
+
interface HTMLElementTagNameMap {
|
21
|
+
['mdc-subcomponent']: SubComponentThemeProvider;
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { css } from "lit";
|
2
|
+
|
3
|
+
const styles = css`
|
4
|
+
:host {
|
5
|
+
--mdc-themeprovider-font-family: "Momentum";
|
6
|
+
--mdc-themeprovider-color-default: var(--mds-color-theme-text-primary-normal);
|
7
|
+
|
8
|
+
font-family: var(--mdc-themeprovider-font-family);
|
9
|
+
color: var(--mdc-themeprovider-color-default);
|
10
|
+
}
|
11
|
+
`;
|
12
|
+
|
13
|
+
export default styles;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { ValueOf } from '../../utils/types';
|
2
|
+
import { THEME_NAMES } from './themeprovider.constants';
|
3
|
+
import type { ThemeClassPrefix, ThemeClassSeparator } from './themeprovider.utils';
|
4
|
+
|
5
|
+
export type ThemeName = ValueOf<typeof THEME_NAMES>;
|
6
|
+
|
7
|
+
export type Theme<T extends ThemeName = ThemeName> = `${ThemeClassPrefix}${ThemeClassSeparator}${T}`;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { Theme, ThemeName } from './themeprovider.types';
|
2
|
+
|
3
|
+
const THEME_CLASS_PREFIX = 'mds-theme-stable' as const;
|
4
|
+
|
5
|
+
export const THEME_CLASS_SEPARATOR = '-' as const;
|
6
|
+
|
7
|
+
const getFullQualifiedTheme = <T extends ThemeName>(themeName: T): Theme =>
|
8
|
+
[THEME_CLASS_PREFIX, themeName].join(THEME_CLASS_SEPARATOR) as Theme<T>;
|
9
|
+
|
10
|
+
const utils = {
|
11
|
+
getFullQualifiedTheme,
|
12
|
+
};
|
13
|
+
|
14
|
+
export default utils;
|
15
|
+
export type ThemeClassPrefix = typeof THEME_CLASS_PREFIX;
|
16
|
+
export type ThemeClassSeparator = typeof THEME_CLASS_SEPARATOR;
|
package/src/index.ts
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
import {
|
2
|
+
Component,
|
3
|
+
Provider,
|
4
|
+
} from './models';
|
5
|
+
|
6
|
+
import ThemeProvider from './components/themeprovider';
|
7
|
+
import Icon from './components/icon';
|
8
|
+
import IconProvider from './components/iconprovider';
|
9
|
+
import Avatar from './components/avatar';
|
10
|
+
import Badge from './components/badge';
|
11
|
+
import Text from './components/text';
|
12
|
+
|
13
|
+
export {
|
14
|
+
Component,
|
15
|
+
Provider,
|
16
|
+
ThemeProvider,
|
17
|
+
Icon,
|
18
|
+
IconProvider,
|
19
|
+
Avatar,
|
20
|
+
Badge,
|
21
|
+
Text,
|
22
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { LitElement } from 'lit';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Core Component class to ultimately be inherited by all Web Components within
|
5
|
+
* this package.
|
6
|
+
*
|
7
|
+
* @public
|
8
|
+
*/
|
9
|
+
class Component extends LitElement {
|
10
|
+
/**
|
11
|
+
* Register `this` extended `Component` Class as a custom element within the
|
12
|
+
* DOM's custom elements registry.
|
13
|
+
*
|
14
|
+
* @remarks
|
15
|
+
* This method must be called in order for this component to be consumable
|
16
|
+
* within the DOM.
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* ```ts
|
20
|
+
* import CustomComponent from './custom-component';
|
21
|
+
*
|
22
|
+
* // Standard registration.
|
23
|
+
* CustomComponent.register();
|
24
|
+
*
|
25
|
+
* // Custom registration.
|
26
|
+
* CustomComponent.register({
|
27
|
+
* name: 'custom-component',
|
28
|
+
* prefix: 'prefix',
|
29
|
+
* });
|
30
|
+
*
|
31
|
+
* export default CustomComponent;
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
*
|
35
|
+
* @returns - Void.
|
36
|
+
*/
|
37
|
+
public static register(namespace: string): void {
|
38
|
+
if (customElements.get(namespace)) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
customElements.define(namespace, this as any);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
export default Component;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* `Component` Class' static `registration()` method options.
|
3
|
+
*
|
4
|
+
* @public
|
5
|
+
*/
|
6
|
+
export interface RegisterOptions {
|
7
|
+
/**
|
8
|
+
* Name to use when registering this `Component` Class' to within DOM.
|
9
|
+
*/
|
10
|
+
name: string;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Name to use when registering this `Component` Class' to within DOM.
|
14
|
+
*/
|
15
|
+
prefix?: string;
|
16
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { ContextProvider } from '@lit-labs/context';
|
2
|
+
import { CSSResult, html } from 'lit';
|
3
|
+
|
4
|
+
import Component from '../component';
|
5
|
+
|
6
|
+
import styles from './provider.styles';
|
7
|
+
|
8
|
+
type ConstructorOptions<C> = {
|
9
|
+
context: { __context__: C };
|
10
|
+
initialValue?: C;
|
11
|
+
};
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Provider Component class to ultimately be inherited by all Provider-type Web
|
15
|
+
* Components within this package.
|
16
|
+
*
|
17
|
+
* @public
|
18
|
+
*/
|
19
|
+
abstract class Provider<C> extends Component {
|
20
|
+
/**
|
21
|
+
* Constructor of the Provider.
|
22
|
+
*
|
23
|
+
* Execute in the constructor of the provider implementation,
|
24
|
+
* like so
|
25
|
+
*
|
26
|
+
* ```
|
27
|
+
* constructor() {
|
28
|
+
* super(TAG_NAME, {initialValue: new ContextClass(defaultValues)});
|
29
|
+
* }
|
30
|
+
* ```
|
31
|
+
* @param host - host of where the context will be hooked onto, e.g. this
|
32
|
+
* @param context - context (returned by createContext)
|
33
|
+
* @param initialValue - initialValue of the ContextClass, like `new ContextClass(defaultValues)`
|
34
|
+
*/
|
35
|
+
constructor({ context, initialValue }: ConstructorOptions<C>) {
|
36
|
+
super();
|
37
|
+
|
38
|
+
this.context = new ContextProvider(this, {
|
39
|
+
context,
|
40
|
+
initialValue,
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Context associated with this provider.
|
46
|
+
*
|
47
|
+
* @remarks
|
48
|
+
* Providing a Context type as a generic when creating extended Provider Class
|
49
|
+
* definitions will help enforce the property validation.
|
50
|
+
*/
|
51
|
+
protected context: ContextProvider<{ __context__: C }>;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Styles associated with this Provider Component.
|
55
|
+
*/
|
56
|
+
public static override styles: CSSResult | Array<CSSResult> = styles;
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Update the context of this Provider and trigger its consumers to update.
|
60
|
+
*
|
61
|
+
* @remarks
|
62
|
+
* This method is called every time this Provider is re-rendered and should
|
63
|
+
* be used to update the local Context based on any deltas between this
|
64
|
+
* Provider's attributes and this Provider's context that caused the
|
65
|
+
* re-render. If the `render()` method is overwritten, this call must be made
|
66
|
+
* manually.
|
67
|
+
*/
|
68
|
+
protected abstract updateContext(): void;
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Render this Provider.
|
72
|
+
*
|
73
|
+
* @remarks
|
74
|
+
* This method calls `updateContext()` then validates whether or not to
|
75
|
+
* update all consumers based on the results of the `shouldUpdateConsumers`
|
76
|
+
* getter.
|
77
|
+
*
|
78
|
+
* @returns - This Provider as an HTML Element.
|
79
|
+
*/
|
80
|
+
public override render() {
|
81
|
+
this.updateContext();
|
82
|
+
|
83
|
+
return html`<slot></slot>`;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
export default Provider;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Meta, ColorPalette, ColorItem } from "@storybook/blocks";
|
2
|
+
|
3
|
+
<Meta title="System/Colors" />
|
4
|
+
|
5
|
+
{/* TODO: automate this such that the color palette is automatically generated from our tokens */}
|
6
|
+
|
7
|
+
<ColorPalette>
|
8
|
+
<ColorItem
|
9
|
+
title="common-text"
|
10
|
+
colors={{
|
11
|
+
white: "#fffffff2",
|
12
|
+
gray: "#ffffffb3",
|
13
|
+
black: "#000000f2",
|
14
|
+
disabled: "#ffffff66",
|
15
|
+
}}
|
16
|
+
/>
|
17
|
+
<ColorItem
|
18
|
+
title="common-text-success"
|
19
|
+
colors={{
|
20
|
+
normal: "#3cc29a",
|
21
|
+
hover: "#9fedd8",
|
22
|
+
}}
|
23
|
+
/>
|
24
|
+
<ColorItem
|
25
|
+
title="button-accent"
|
26
|
+
colors={{
|
27
|
+
normal: "#1170cf",
|
28
|
+
hover: "#0353a8",
|
29
|
+
pressed: "#063a75"
|
30
|
+
}}
|
31
|
+
/>
|
32
|
+
</ColorPalette>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Meta, IconGallery, IconItem } from "@storybook/blocks";
|
2
|
+
|
3
|
+
<Meta title="System/Icons" />
|
4
|
+
|
5
|
+
{/* TODO: automate this such that the icon gallery is automatically generated from our icons */}
|
6
|
+
|
7
|
+
<IconGallery>
|
8
|
+
<IconItem name="3d-object-bold">
|
9
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
10
|
+
<path d="M27.776 6.823 16.78 2.155a2.02 2.02 0 0 0-1.546 0L4.231 6.822A1.995 1.995 0 0 0 3 8.667v14.667a1.993 1.993 0 0 0 1.225 1.843l11.016 4.669a2.033 2.033 0 0 0 1.545-.002l10.984-4.666A1.994 1.994 0 0 0 29 23.333V8.666a1.992 1.992 0 0 0-1.224-1.843ZM16.003 3.998l9.402 3.99-9.425 3.929-9.397-3.922 9.42-3.997ZM5.006 9.504 15 13.675v13.896L5 23.334l.006-13.83Zm21.987 13.832L17 27.584V13.658l10-4.167v13.842l-.007.003Z" />
|
11
|
+
</svg>
|
12
|
+
</IconItem>
|
13
|
+
</IconGallery>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Meta, Typeset } from "@storybook/blocks";
|
2
|
+
|
3
|
+
<Meta title="System/Typography" />
|
4
|
+
|
5
|
+
{/* TODO: automate this such that typeset is automatically generated from our font package */}
|
6
|
+
|
7
|
+
{/* to be able to pass in textTransform to the typeset block, we would
|
8
|
+
need to do something similar like:
|
9
|
+
https://github.com/storybookjs/storybook/pull/15302
|
10
|
+
it looks like the existing lineHeight doesn't work in mdx though - has to be investigated */}
|
11
|
+
|
12
|
+
### Heading 1
|
13
|
+
<Typeset
|
14
|
+
fontSizes={["7.5rem"]}
|
15
|
+
fontWeight="700"
|
16
|
+
sampleText="Lorem ipsum dolor sit amet, consectectur adipiscing elit."
|
17
|
+
fontFamily='"Momentum"'
|
18
|
+
fontStyle="normal"
|
19
|
+
lineHeight="48px"
|
20
|
+
/>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { LitElement } from 'lit';
|
2
|
+
import { property } from 'lit/decorators.js';
|
3
|
+
|
4
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
5
|
+
|
6
|
+
export interface DisabledMixinInterface {
|
7
|
+
disabled: boolean;
|
8
|
+
}
|
9
|
+
|
10
|
+
export const DisabledMixin = <T extends Constructor<LitElement>>(
|
11
|
+
superClass: T,
|
12
|
+
) => {
|
13
|
+
class InnerMixinClass extends superClass {
|
14
|
+
@property({ reflect: true, type: Boolean })
|
15
|
+
public disabled = false;
|
16
|
+
}
|
17
|
+
// Cast return type to your mixin's interface intersected with the superClass type
|
18
|
+
return InnerMixinClass as Constructor<DisabledMixinInterface> & T;
|
19
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { LitElement } from 'lit';
|
2
|
+
import { property } from 'lit/decorators.js';
|
3
|
+
|
4
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
5
|
+
|
6
|
+
export interface TabIndexMixinInterface {
|
7
|
+
tabIndex: number;
|
8
|
+
}
|
9
|
+
|
10
|
+
export const TabIndexMixin = <T extends Constructor<LitElement>>(
|
11
|
+
superClass: T,
|
12
|
+
) => {
|
13
|
+
class InnerMixinClass extends superClass {
|
14
|
+
@property({ reflect: true, type: Number, attribute: 'tabindex' })
|
15
|
+
public override tabIndex = 0;
|
16
|
+
}
|
17
|
+
// Cast return type to your mixin's interface intersected with the superClass type
|
18
|
+
return InnerMixinClass as Constructor<TabIndexMixinInterface> & T;
|
19
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Context, ContextConsumer } from '@lit-labs/context';
|
2
|
+
import { ReactiveElement } from 'lit';
|
3
|
+
|
4
|
+
type ConsumeOptions<C> = {
|
5
|
+
host: ReactiveElement;
|
6
|
+
context: C;
|
7
|
+
subscribe?:boolean
|
8
|
+
}
|
9
|
+
const consume = <C extends Context<unknown, unknown>>(options: ConsumeOptions<C>) => {
|
10
|
+
const { host, context, subscribe } = options;
|
11
|
+
|
12
|
+
return new ContextConsumer<C, typeof host>(host, {
|
13
|
+
context,
|
14
|
+
subscribe: subscribe ?? true,
|
15
|
+
});
|
16
|
+
};
|
17
|
+
|
18
|
+
const providerUtils = {
|
19
|
+
consume,
|
20
|
+
};
|
21
|
+
export default providerUtils;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/* eslint-disable implicit-arrow-linebreak */
|
2
|
+
/* eslint-disable max-len */
|
3
|
+
import CONSTANTS from './constants';
|
4
|
+
|
5
|
+
// make ReturnType a String Literal to make it usable in the HTMLElementTagNameMap per component
|
6
|
+
// using Template Literal Types: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
|
7
|
+
type ReturnType<ComponentName extends string> =
|
8
|
+
`${typeof CONSTANTS.NAMESPACE.PREFIX}${typeof CONSTANTS.NAMESPACE.SEPARATOR}${ComponentName}`;
|
9
|
+
|
10
|
+
const constructTagName = <ComponentName extends string>(componentName: ComponentName): ReturnType<ComponentName> =>
|
11
|
+
[CONSTANTS.NAMESPACE.PREFIX, componentName].join(CONSTANTS.NAMESPACE.SEPARATOR) as ReturnType<ComponentName>;
|
12
|
+
|
13
|
+
export default {
|
14
|
+
constructTagName,
|
15
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export type ValueOf<T> = T[keyof T];
|
package/tsconfig.json
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
{
|
2
|
+
"extends": "../../../config/typescript/tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"target": "es2019",
|
5
|
+
"module": "es2020",
|
6
|
+
"lib": [
|
7
|
+
"es2020",
|
8
|
+
"DOM",
|
9
|
+
"DOM.Iterable"
|
10
|
+
],
|
11
|
+
"declaration": true,
|
12
|
+
"declarationMap": true,
|
13
|
+
"sourceMap": true,
|
14
|
+
"inlineSources": true,
|
15
|
+
"outDir": "./dist",
|
16
|
+
"rootDir": "./",
|
17
|
+
"strict": true,
|
18
|
+
"noUnusedLocals": true,
|
19
|
+
"noUnusedParameters": true,
|
20
|
+
"noImplicitReturns": true,
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
22
|
+
"noImplicitAny": true,
|
23
|
+
"noImplicitThis": true,
|
24
|
+
"moduleResolution": "node",
|
25
|
+
"allowSyntheticDefaultImports": true,
|
26
|
+
"experimentalDecorators": true,
|
27
|
+
"forceConsistentCasingInFileNames": true,
|
28
|
+
"noImplicitOverride": true,
|
29
|
+
"useDefineForClassFields": false,
|
30
|
+
"plugins": [
|
31
|
+
{
|
32
|
+
"name": "ts-lit-plugin",
|
33
|
+
"strict": true
|
34
|
+
}
|
35
|
+
]
|
36
|
+
},
|
37
|
+
"include": [
|
38
|
+
"src/**/*.ts",
|
39
|
+
"config",
|
40
|
+
".eslintrc.js"
|
41
|
+
],
|
42
|
+
"exclude": [
|
43
|
+
"node_modules"
|
44
|
+
],
|
45
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
{
|
2
|
+
"extends": "../../../config/typescript/tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"target": "es2019",
|
5
|
+
"module": "CommonJS",
|
6
|
+
"lib": [
|
7
|
+
"es2020",
|
8
|
+
"DOM",
|
9
|
+
"DOM.Iterable"
|
10
|
+
],
|
11
|
+
"declaration": true,
|
12
|
+
"declarationMap": false,
|
13
|
+
"declarationDir": "./dist",
|
14
|
+
"sourceMap": false,
|
15
|
+
"inlineSources": false,
|
16
|
+
"outDir": "./dist",
|
17
|
+
"strict": true,
|
18
|
+
"noUnusedLocals": true,
|
19
|
+
"noUnusedParameters": true,
|
20
|
+
"noImplicitReturns": true,
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
22
|
+
"noImplicitAny": true,
|
23
|
+
"noImplicitThis": true,
|
24
|
+
"moduleResolution": "node",
|
25
|
+
"allowSyntheticDefaultImports": true,
|
26
|
+
"experimentalDecorators": true,
|
27
|
+
"forceConsistentCasingInFileNames": true,
|
28
|
+
"noImplicitOverride": true,
|
29
|
+
"useDefineForClassFields": false,
|
30
|
+
"removeComments": false,
|
31
|
+
"plugins": [
|
32
|
+
{
|
33
|
+
"name": "ts-lit-plugin",
|
34
|
+
"strict": true
|
35
|
+
}
|
36
|
+
],
|
37
|
+
},
|
38
|
+
"files": [
|
39
|
+
"src/index.ts"
|
40
|
+
],
|
41
|
+
"exclude": [
|
42
|
+
"**/*.e2e-test.ts",
|
43
|
+
"**/*.fixtures.ts",
|
44
|
+
"**/*.stories.ts",
|
45
|
+
"node_modules"
|
46
|
+
],
|
47
|
+
}
|