@descope-ui/descope-text 0.0.1

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,35 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { getStoryUrl, loopConfig } from 'e2e-utils';
3
+
4
+ const componentAttributes = {
5
+ text: 'Test Text',
6
+ variant: ['h1', 'h2', 'h3', 'subtitle1', 'subtitle2', 'body1', 'body2'],
7
+ mode: ['primary', 'secondary', 'success', 'error'],
8
+ 'text-align': ['left', 'center', 'right'],
9
+ 'hide-when-empty': ['true'],
10
+ };
11
+
12
+ const storyName = 'descope-text';
13
+ const componentName = 'descope-text';
14
+
15
+ test.describe('theme', () => {
16
+ loopConfig(componentAttributes, (attr, value) => {
17
+ test(`${attr}: ${value}`, async ({ page }) => {
18
+ await page.goto(getStoryUrl(storyName, { [attr]: value }));
19
+ const component = page.locator(componentName);
20
+ expect(await component.screenshot()).toMatchSnapshot();
21
+ });
22
+ });
23
+
24
+ test(`full-width: false`, async ({ page }) => {
25
+ await page.goto(getStoryUrl(storyName, { 'full-width': false }));
26
+ const component = page.locator(componentName);
27
+ expect(await component.screenshot()).toMatchSnapshot();
28
+ });
29
+
30
+ test(`direction: rtl`, async ({ page }) => {
31
+ await page.goto(getStoryUrl(storyName, { direction: 'rtl', text: '-Hello World' }));
32
+ const component = page.locator(componentName);
33
+ expect(await component.screenshot()).toMatchSnapshot();
34
+ });
35
+ });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@descope-ui/descope-text",
3
+ "version": "0.0.1",
4
+ "exports": {
5
+ ".": {
6
+ "import": "./src/component/index.js"
7
+ },
8
+ "./theme": {
9
+ "import": "./src/theme.js"
10
+ },
11
+ "./class": {
12
+ "import": "./src/component/TextClass.js"
13
+ }
14
+ },
15
+ "devDependencies": {
16
+ "@playwright/test": "1.38.1",
17
+ "e2e-utils": "0.0.1"
18
+ },
19
+ "dependencies": {
20
+ "@descope-ui/common": "0.0.1",
21
+ "@descope-ui/theme-globals": "0.0.1"
22
+ },
23
+ "publishConfig": {
24
+ "link-workspace-packages": false
25
+ },
26
+ "scripts": {
27
+ "test": "echo 'No tests defined' && exit 0",
28
+ "test:e2e": "echo 'No e2e tests defined' && exit 0"
29
+ }
30
+ }
package/project.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@descope-ui/descope-text",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "packages/web-components/components/descope-text/src",
5
+ "projectType": "library",
6
+ "tags": []
7
+ }
@@ -0,0 +1,73 @@
1
+ import {
2
+ createStyleMixin,
3
+ draggableMixin,
4
+ componentNameValidationMixin,
5
+ } from '@descope-ui/common/components-mixins';
6
+ import { compose } from '@descope-ui/common/utils';
7
+ import {
8
+ getComponentName,
9
+ observeChildren,
10
+ } from '@descope-ui/common/components-helpers';
11
+ import { createBaseClass } from '@descope-ui/common/base-classes';
12
+
13
+ export const componentName = getComponentName('text');
14
+
15
+ class RawText extends createBaseClass({
16
+ componentName,
17
+ baseSelector: ':host > slot',
18
+ }) {
19
+ constructor() {
20
+ super();
21
+
22
+ this.attachShadow({ mode: 'open' }).innerHTML = `
23
+ <style>
24
+ :host {
25
+ display: inline-block;
26
+ line-height: 1em;
27
+ }
28
+ :host > slot {
29
+ width: 100%;
30
+ display: inline-block;
31
+ }
32
+ </style>
33
+ <slot part="text-wrapper"></slot>
34
+ `;
35
+ }
36
+
37
+ get hideWhenEmpty() {
38
+ return this.getAttribute('hide-when-empty') === 'true';
39
+ }
40
+
41
+ init() {
42
+ super.init();
43
+
44
+ observeChildren(this, () => {
45
+ const hasChildren = !!this.childNodes.length;
46
+ this.style.display = !hasChildren && this.hideWhenEmpty ? 'none' : '';
47
+ });
48
+ }
49
+ }
50
+
51
+ export const TextClass = compose(
52
+ createStyleMixin({
53
+ mappings: {
54
+ hostWidth: { selector: () => ':host', property: 'width' },
55
+ hostDirection: { selector: () => ':host', property: 'direction' },
56
+ fontSize: {},
57
+ textColor: { property: 'color' },
58
+ textLineHeight: { property: 'line-height' },
59
+ textLetterSpacing: { property: 'letter-spacing' },
60
+ textShadow: {},
61
+ textAlign: {},
62
+ textTransform: {},
63
+ fontFamily: {},
64
+ fontStyle: {},
65
+ fontWeight: {},
66
+ borderWidth: {},
67
+ borderStyle: {},
68
+ borderColor: {},
69
+ },
70
+ }),
71
+ draggableMixin,
72
+ componentNameValidationMixin,
73
+ )(RawText);
@@ -0,0 +1,5 @@
1
+ import { componentName, TextClass } from './TextClass';
2
+
3
+ customElements.define(componentName, TextClass);
4
+
5
+ export { TextClass };
package/src/theme.js ADDED
@@ -0,0 +1,91 @@
1
+ import globals from '@descope-ui/theme-globals';
2
+ import { getThemeRefs } from '@descope-ui/common/theme-helpers';
3
+ import { TextClass } from './component/TextClass';
4
+
5
+ const globalRefs = getThemeRefs(globals);
6
+ const vars = TextClass.cssVarList;
7
+
8
+ const text = {
9
+ [vars.hostDirection]: globalRefs.direction,
10
+ [vars.textLineHeight]: '1.35em',
11
+ [vars.textAlign]: 'left',
12
+ [vars.textColor]: globalRefs.colors.surface.dark,
13
+
14
+ variant: {
15
+ h1: {
16
+ [vars.fontSize]: globalRefs.typography.h1.size,
17
+ [vars.fontWeight]: globalRefs.typography.h1.weight,
18
+ [vars.fontFamily]: globalRefs.typography.h1.font,
19
+ },
20
+ h2: {
21
+ [vars.fontSize]: globalRefs.typography.h2.size,
22
+ [vars.fontWeight]: globalRefs.typography.h2.weight,
23
+ [vars.fontFamily]: globalRefs.typography.h2.font,
24
+ },
25
+ h3: {
26
+ [vars.fontSize]: globalRefs.typography.h3.size,
27
+ [vars.fontWeight]: globalRefs.typography.h3.weight,
28
+ [vars.fontFamily]: globalRefs.typography.h3.font,
29
+ },
30
+ subtitle1: {
31
+ [vars.fontSize]: globalRefs.typography.subtitle1.size,
32
+ [vars.fontWeight]: globalRefs.typography.subtitle1.weight,
33
+ [vars.fontFamily]: globalRefs.typography.subtitle1.font,
34
+ },
35
+ subtitle2: {
36
+ [vars.fontSize]: globalRefs.typography.subtitle2.size,
37
+ [vars.fontWeight]: globalRefs.typography.subtitle2.weight,
38
+ [vars.fontFamily]: globalRefs.typography.subtitle2.font,
39
+ },
40
+ body1: {
41
+ [vars.fontSize]: globalRefs.typography.body1.size,
42
+ [vars.fontWeight]: globalRefs.typography.body1.weight,
43
+ [vars.fontFamily]: globalRefs.typography.body1.font,
44
+ },
45
+ body2: {
46
+ [vars.fontSize]: globalRefs.typography.body2.size,
47
+ [vars.fontWeight]: globalRefs.typography.body2.weight,
48
+ [vars.fontFamily]: globalRefs.typography.body2.font,
49
+ },
50
+ },
51
+
52
+ mode: {
53
+ primary: {
54
+ [vars.textColor]: globalRefs.colors.surface.contrast,
55
+ },
56
+ secondary: {
57
+ [vars.textColor]: globalRefs.colors.surface.dark,
58
+ },
59
+ error: {
60
+ [vars.textColor]: globalRefs.colors.error.main,
61
+ },
62
+ success: {
63
+ [vars.textColor]: globalRefs.colors.success.main,
64
+ },
65
+ },
66
+
67
+ textAlign: {
68
+ right: { [vars.textAlign]: 'right' },
69
+ left: { [vars.textAlign]: 'left' },
70
+ center: { [vars.textAlign]: 'center' },
71
+ },
72
+
73
+ _fullWidth: {
74
+ [vars.hostWidth]: '100%',
75
+ },
76
+
77
+ _italic: {
78
+ [vars.fontStyle]: 'italic',
79
+ },
80
+
81
+ _uppercase: {
82
+ [vars.textTransform]: 'uppercase',
83
+ },
84
+
85
+ _lowercase: {
86
+ [vars.textTransform]: 'lowercase',
87
+ },
88
+ };
89
+
90
+ export default text;
91
+ export { vars };
@@ -0,0 +1,55 @@
1
+ import { componentName } from '../src/component/TextClass';
2
+ import {
3
+ textContentControl,
4
+ textAlignControl,
5
+ modeControl,
6
+ fullWidthControl,
7
+ typographyVariantControl,
8
+ directionControl,
9
+ } from '@descope-ui/common/sb-controls';
10
+
11
+ const Template = ({
12
+ variant,
13
+ mode,
14
+ 'text-align': textAlign,
15
+ 'full-width': fullWidth,
16
+ text,
17
+ 'hide-when-empty': hideWhenEmpty,
18
+ direction,
19
+ }) => `
20
+ <descope-text
21
+ mode="${mode || ''}"
22
+ variant="${variant || ''}"
23
+ full-width="${fullWidth || false}"
24
+ text-align="${textAlign}"
25
+ hide-when-empty="${hideWhenEmpty}"
26
+ st-host-direction="${direction ?? ''}"
27
+ >${text}</descope-text>
28
+ `;
29
+
30
+ export default {
31
+ component: componentName,
32
+ title: 'descope-text',
33
+ parameters: {
34
+ panelPosition: 'right',
35
+ controls: { expanded: true },
36
+ },
37
+ argTypes: {
38
+ ...textContentControl,
39
+ ...modeControl,
40
+ ...textAlignControl,
41
+ ...fullWidthControl,
42
+ ...typographyVariantControl,
43
+ ...directionControl,
44
+ },
45
+ };
46
+
47
+ export const Default = Template.bind({});
48
+
49
+ Default.args = {
50
+ text: 'Lorem Ipsum',
51
+ variant: 'h1',
52
+ mode: 'primary',
53
+ 'hide-when-empty': false,
54
+ fullWidth: true, // full-width is true by default for test purposes, which expect this as default and test the FALSE override only
55
+ };