@gem-sdk/system 1.58.0-dev.134 → 1.58.0-dev.135

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.
Files changed (40) hide show
  1. package/dist/cjs/component/createAttr.js +34 -0
  2. package/dist/cjs/component/createClass.js +38 -0
  3. package/dist/cjs/component/createContent.js +19 -0
  4. package/dist/cjs/component/createStateOrContext.js +55 -0
  5. package/dist/cjs/component/createStyle.js +42 -0
  6. package/dist/cjs/component/utils/toCamelCaseKeys.js +15 -0
  7. package/dist/cjs/index.js +19 -0
  8. package/dist/esm/component/createAttr.js +32 -0
  9. package/dist/esm/component/createClass.js +36 -0
  10. package/dist/esm/component/createContent.js +17 -0
  11. package/dist/esm/component/createStateOrContext.js +53 -0
  12. package/dist/esm/component/createStyle.js +39 -0
  13. package/dist/esm/component/utils/toCamelCaseKeys.js +13 -0
  14. package/dist/esm/index.js +5 -0
  15. package/dist/types/index.d.ts +30 -0
  16. package/package.json +10 -6
  17. package/src/component/Research.txt +53 -0
  18. package/src/component/__tests__/createAttr.test.ts +62 -0
  19. package/src/component/__tests__/createClass.test.ts +68 -0
  20. package/src/component/__tests__/createContent.test.ts +52 -0
  21. package/src/component/__tests__/createStateOrContext.test.ts +129 -0
  22. package/src/component/__tests__/createStyle.test.ts +63 -0
  23. package/src/component/createAttr.ts +44 -0
  24. package/src/component/createClass.ts +48 -0
  25. package/src/component/createContent.ts +20 -0
  26. package/src/component/createStateOrContext.ts +70 -0
  27. package/src/component/createStyle.ts +53 -0
  28. package/src/component/types.ts +9 -0
  29. package/src/component/utils/__tests__/toCamelCaseKeys.test.ts +79 -0
  30. package/src/component/utils/toCamelCaseKeys.ts +20 -0
  31. package/src/e2e-tests/README.md +1 -0
  32. package/src/examples/components/text/DemoText.liquid.ts +40 -0
  33. package/src/examples/components/text/DemoText.tsx +41 -0
  34. package/src/examples/components/text/common/__tests__/globalTypoClasses.test.ts +11 -0
  35. package/src/examples/components/text/common/getAttr.ts +7 -0
  36. package/src/examples/components/text/common/getStyle.ts +5 -0
  37. package/src/examples/components/text/common/globalTypoClasses.ts +5 -0
  38. package/src/examples/components/text/e2e-tests/DemoText.spec.tsx +23 -0
  39. package/src/examples/components/text/e2e-tests/DemoText.tsx +23 -0
  40. package/src/validator/README.md +1 -0
@@ -0,0 +1,40 @@
1
+ import {
2
+ createAttr,
3
+ createClass,
4
+ createContent,
5
+ createStateOrContext,
6
+ createStyle,
7
+ } from '../../../index';
8
+ import { getAttr } from './common/getAttr';
9
+ import { getStyle } from './common/getStyle';
10
+ import { globalTypoClasses } from './common/globalTypoClasses';
11
+ import type { TextProps } from './DemoText';
12
+ import { template } from '@gem-sdk/core';
13
+
14
+ const Text = ({ product, text }: TextProps) => {
15
+ const state = createStateOrContext({
16
+ productId: product.id,
17
+ });
18
+
19
+ const attrs = createAttr({
20
+ ...getAttr({ product }),
21
+ });
22
+ const styles = createStyle({
23
+ ...getStyle(),
24
+ });
25
+ const classes = createClass({
26
+ ...globalTypoClasses(),
27
+ });
28
+
29
+ const content = createContent(text);
30
+
31
+ return template`
32
+ <div ${attrs} gp-data="${state}">
33
+ <label class="${{ classes }}" style="${styles}">
34
+ ${content}
35
+ </label>
36
+ </div>
37
+ `;
38
+ };
39
+
40
+ export default Text;
@@ -0,0 +1,41 @@
1
+ import {
2
+ createAttrReact,
3
+ createClassReact,
4
+ createContentReact,
5
+ createStyleReact,
6
+ } from '../../../index';
7
+ import { globalTypoClasses } from './common/globalTypoClasses';
8
+
9
+ export type TextProps = {
10
+ product: {
11
+ id: string;
12
+ };
13
+ text: string;
14
+ };
15
+
16
+ const Text: React.FC<TextProps> = ({ product, text }) => {
17
+ const attrs = createAttrReact({
18
+ 'data-gp-product-id': product.id,
19
+ });
20
+ const styles = createStyleReact({
21
+ 'font-size': '16px',
22
+ });
23
+
24
+ const typoClasses = globalTypoClasses();
25
+ const classes = createClassReact({
26
+ 'gp-text': true,
27
+ ...typoClasses,
28
+ });
29
+
30
+ const content = createContentReact(text);
31
+
32
+ return (
33
+ <div {...attrs}>
34
+ <label className={classes} style={styles}>
35
+ {content}
36
+ </label>
37
+ </div>
38
+ );
39
+ };
40
+
41
+ export default Text;
@@ -0,0 +1,11 @@
1
+ import { describe, test, expect } from '@jest/globals';
2
+ import { globalTypoClasses } from '../globalTypoClasses';
3
+
4
+ describe('globalTypoClasses', () => {
5
+ test('Test case 1', () => {
6
+ const classes = globalTypoClasses();
7
+ expect(classes).toEqual({
8
+ 'gp-global-h1': true,
9
+ });
10
+ });
11
+ });
@@ -0,0 +1,7 @@
1
+ import type { TextProps } from '../DemoText';
2
+
3
+ export const getAttr = ({ product }: { product: TextProps['product'] }) => {
4
+ return {
5
+ 'data-gp-product-id': product.id,
6
+ };
7
+ };
@@ -0,0 +1,5 @@
1
+ export const getStyle = () => {
2
+ return {
3
+ 'font-size': '16px',
4
+ };
5
+ };
@@ -0,0 +1,5 @@
1
+ export const globalTypoClasses = (): Record<string, boolean> => {
2
+ return {
3
+ 'gp-global-h1': true,
4
+ };
5
+ };
@@ -0,0 +1,23 @@
1
+ import { test, expect } from '@playwright/experimental-ct-react';
2
+ import type { TextProps } from "../DemoText";
3
+ import DemoText from "../DemoText"
4
+ import DemoTextLiquid from "../DemoText.liquid"
5
+
6
+ test('should work', async ({ mount }, testInfo) => {
7
+ const props: TextProps = {
8
+ product: {
9
+ id: "1"
10
+ },
11
+ text: "Demo test"
12
+ }
13
+
14
+ const component = await mount((
15
+ <div>
16
+ <div className='react-el'><DemoText {...props}/></div>
17
+ <div className='liquid-el'><div dangerouslySetInnerHTML={{__html: DemoTextLiquid(props)}}></div></div>
18
+ </div>
19
+ ));
20
+
21
+ await expect(component.locator('.react-el')).toHaveScreenshot(`${testInfo.title}.png`);
22
+ await expect(component.locator('.liquid-el')).toHaveScreenshot(`${testInfo.title}.png`);
23
+ });
@@ -0,0 +1,23 @@
1
+ import type { E2ETests } from '../../../../component/types';
2
+ import type { TextProps } from '../DemoText';
3
+ import DemoTextReact from '../DemoText';
4
+ import DemoTextLiquid from '../DemoText.liquid';
5
+
6
+ export const e2eDemoText = (): E2ETests => {
7
+ return {
8
+ 'DemoText basic': async () => {
9
+ const props: TextProps = {
10
+ product: {
11
+ id: '1',
12
+ },
13
+ text: 'Demo test',
14
+ };
15
+
16
+ return {
17
+ props,
18
+ reactComponent: DemoTextReact,
19
+ liquidComponent: DemoTextLiquid,
20
+ };
21
+ },
22
+ };
23
+ };
@@ -0,0 +1 @@
1
+ Đây là folder chưa các func validate component setting