Skip to content

Commit 7b55d5f

Browse files
authored
Drop fast react wrapper (#100)
* Add metadata for generating react components * New react components * First partial fix * Prettify * Improve typing * Simplify component types * Fix reference to custom element * Package custom elements definitions * Keep event naming * Build dynamically custom-element def * Remove dist file exception * Restore datefield react component * Lint the code --------- Co-authored-by: Frédéric Collonval <[email protected]>
1 parent 68d98ff commit 7b55d5f

File tree

199 files changed

+5924
-1485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+5924
-1485
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.bundle.*
22
lib/
3+
!packages/react-components/lib/
34
node_modules/
45
*.log
56
.eslintcache
@@ -30,11 +31,10 @@ __pycache__/
3031
.Python
3132
build/
3233
develop-eggs/
33-
dist/
34+
**/dist/*
3435
downloads/
3536
eggs/
3637
.eggs/
37-
lib/
3838
lib64/
3939
parts/
4040
sdist/

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ npm-debug.log*
2727
yarn-debug.log*
2828
yarn-error.log*
2929
tests-out/
30+
31+
!packages/react-components/lib

CONTRIBUTING.md

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ cd packages/components
3030
yarn start
3131
```
3232

33+
### React components
34+
35+
The react components wrapper are initialized using [custom-element-react-wrappers](https://github.com/break-stuff/cem-tools/tree/main/packages/react-wrappers).
36+
The initialization can be reproduced by running in `packages/components` the script `yarn run build:react`.
37+
Unfortunately the initial code needs lots of changes to be usable in this case:
38+
39+
- Changing the typing to inherit from `React.AllHTMLAttributes` - minus some event handlers that needs to be overridden.
40+
- Changing `useImperativeHandle` to expose the full HTMLElement using:
41+
42+
```js
43+
useImperativeHandle(forwardedRef, () => ref.current, [ref.current]);
44+
```
45+
46+
- Remove internal fast-specific properties like `$presentation`, `styles` and `template`.
47+
- The tag name, the properties and the events are extracted from the doc string of
48+
the element class definition in `packages/components`. You may need to add some
49+
new doc tags to get all the properties and events.
50+
3351
### JupyterLab demo extension
3452

3553
To test locally the JupyterLab demo extension, using `conda` package manager:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* global process */
2+
import { customElementReactWrapperPlugin } from 'custom-element-react-wrappers';
3+
4+
/**
5+
* Custom element manifest plugin to remove the
6+
* Jupyter prefix in the element class name to
7+
* get a better naming for the generated react components.
8+
*/
9+
function renameClassElement() {
10+
return {
11+
name: 'rename-class-element-plugin',
12+
packageLinkPhase({ customElementsManifest, context }) {
13+
customElementsManifest.modules.forEach(module => {
14+
module.declarations.forEach(declaration => {
15+
// Remove the prefix `Jupyter` for simpler naming
16+
if (declaration.tagName && declaration.name.startsWith('Jupyter')) {
17+
declaration.name = declaration.name.slice(7);
18+
}
19+
});
20+
});
21+
}
22+
};
23+
}
24+
25+
const plugins = [renameClassElement()];
26+
27+
if (process.env.BUILD_REACT) {
28+
plugins.push(
29+
customElementReactWrapperPlugin({
30+
outdir: '../react-components/lib',
31+
modulePath: (className, tagName) => '@jupyter/web-components'
32+
})
33+
);
34+
}
35+
36+
export default {
37+
fast: true,
38+
outdir: 'dist',
39+
dependencies: true,
40+
globs: ['src/**/index.ts'],
41+
exclude: ['src/index.ts', 'src/styles', 'src/utilities'],
42+
plugins
43+
};

packages/components/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
"scripts": {
2626
"start": "storybook dev -p 6006",
2727
"start:ci": "storybook dev -p 6006 --ci --quiet",
28-
"build": "rollup -c && tsc -p ./tsconfig.json",
28+
"build": "rollup -c && tsc -p ./tsconfig.json && custom-elements-manifest analyze",
2929
"build:docs": "storybook build",
30+
"build:react": "BUILD_REACT=1 custom-elements-manifest analyze",
3031
"clean": "yarn clean:lib && yarn clean:test",
3132
"clean:lib": "rimraf dist",
3233
"clean:test": "rimraf test-results tests-out/**/*.js tests-out/**/*.js.map tsconfig.playwright.tsbuildinfo",
@@ -49,6 +50,7 @@
4950
"devDependencies": {
5051
"@babel/core": "^7.22.5",
5152
"@babel/preset-env": "^7.22.5",
53+
"@custom-elements-manifest/analyzer": "^0.10.2",
5254
"@fortawesome/fontawesome-svg-core": "^1.2.36",
5355
"@fortawesome/free-solid-svg-icons": "^5.15.4",
5456
"@microsoft/api-extractor": "^7.36.0",
@@ -69,6 +71,7 @@
6971
"@types/node": "^18.0.0",
7072
"@types/webpack-env": "^1.15.2",
7173
"@typescript-eslint/eslint-plugin": "^5.60.1",
74+
"custom-element-react-wrappers": "^1.6.0",
7275
"eslint": "^8.43.0",
7376
"eslint-config-prettier": "^8.8.0",
7477
"eslint-plugin-import": "^2.25.2",
@@ -98,5 +101,6 @@
98101
},
99102
"publishConfig": {
100103
"access": "public"
101-
}
104+
},
105+
"customElements": "dist/custom-elements.json"
102106
}

packages/components/src/accordion-item/index.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import {
99
} from '@microsoft/fast-foundation';
1010
import { accordionItemStyles as styles } from './accordion-item.styles.js';
1111

12+
/**
13+
* Accordion item class
14+
*
15+
* @public
16+
* @tagname jp-accordion-item
17+
*/
18+
class JupyterAccordionItem extends AccordionItem {}
19+
1220
/**
1321
* A function that returns a {@link @microsoft/fast-foundation#AccordionItem} registration for configuring the component with a DesignSystem.
1422
* Implements {@link @microsoft/fast-foundation#accordionItemTemplate}
@@ -18,11 +26,13 @@ import { accordionItemStyles as styles } from './accordion-item.styles.js';
1826
* @remarks
1927
* Generates HTML Element: `<jp-accordion-item>`
2028
*/
21-
export const jpAccordionItem = AccordionItem.compose<AccordionItemOptions>({
22-
baseName: 'accordion-item',
23-
template,
24-
styles,
25-
collapsedIcon: /* html */ `
29+
export const jpAccordionItem =
30+
JupyterAccordionItem.compose<AccordionItemOptions>({
31+
baseName: 'accordion-item',
32+
baseClass: AccordionItem,
33+
template,
34+
styles,
35+
collapsedIcon: /* html */ `
2636
<svg
2737
width="20"
2838
height="20"
@@ -36,7 +46,7 @@ export const jpAccordionItem = AccordionItem.compose<AccordionItemOptions>({
3646
/>
3747
</svg>
3848
`,
39-
expandedIcon: /* html */ `
49+
expandedIcon: /* html */ `
4050
<svg
4151
width="20"
4252
height="20"
@@ -51,12 +61,8 @@ export const jpAccordionItem = AccordionItem.compose<AccordionItemOptions>({
5161
/>
5262
</svg>
5363
`
54-
});
64+
});
5565

56-
/**
57-
* Base class for Accordion item
58-
* @public
59-
*/
60-
export { AccordionItem };
66+
export { JupyterAccordionItem as AccordionItem };
6167

6268
export { styles as accordionItemStyles };

packages/components/src/accordion/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import { accordionStyles as styles } from './accordion.styles.js';
1010

1111
export * from '../accordion-item/index.js';
1212

13+
/**
14+
* Accordion class
15+
*
16+
* @public
17+
* @tagname jp-accordion
18+
*/
19+
class JupyterAccordion extends Accordion {}
20+
1321
/**
1422
* A function that returns a {@link @microsoft/fast-foundation#Accordion} registration for configuring the component with a DesignSystem.
1523
* Implements {@link @microsoft/fast-foundation#accordionTemplate}
@@ -19,16 +27,13 @@ export * from '../accordion-item/index.js';
1927
* @remarks
2028
* Generates HTML Element: `<jp-accordion>`
2129
*/
22-
export const jpAccordion = Accordion.compose({
30+
export const jpAccordion = JupyterAccordion.compose({
2331
baseName: 'accordion',
32+
baseClass: Accordion,
2433
template,
2534
styles
2635
});
2736

28-
/**
29-
* Base class for Accordion
30-
* @public
31-
*/
32-
export { Accordion };
37+
export { JupyterAccordion as Accordion };
3338

3439
export { styles as accordionStyles };

packages/components/src/anchor/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
// Distributed under the terms of the Modified BSD License.
44

55
import { attr } from '@microsoft/fast-element';
6-
import {
7-
Anchor as FoundationAnchor,
8-
anchorTemplate as template
9-
} from '@microsoft/fast-foundation';
6+
import { Anchor, anchorTemplate as template } from '@microsoft/fast-foundation';
107
import { ButtonAppearance } from '../button/index.js';
118
import { anchorStyles as styles } from './anchor.styles.js';
129

@@ -17,10 +14,11 @@ import { anchorStyles as styles } from './anchor.styles.js';
1714
export type AnchorAppearance = ButtonAppearance | 'hypertext';
1815

1916
/**
20-
* Base class for Anchor
17+
* Anchor class
2118
* @public
19+
* @tagname jp-anchor
2220
*/
23-
export class Anchor extends FoundationAnchor {
21+
class JupyterAnchor extends Anchor {
2422
/**
2523
* The appearance the anchor should have.
2624
*
@@ -80,14 +78,16 @@ export class Anchor extends FoundationAnchor {
8078
*
8179
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus | delegatesFocus}
8280
*/
83-
export const jpAnchor = Anchor.compose({
81+
export const jpAnchor = JupyterAnchor.compose({
8482
baseName: 'anchor',
85-
baseClass: FoundationAnchor,
83+
baseClass: Anchor,
8684
template,
8785
styles,
8886
shadowOptions: {
8987
delegatesFocus: true
9088
}
9189
});
9290

91+
export { JupyterAnchor as Anchor };
92+
9393
export { styles as anchorStyles };

packages/components/src/anchored-region/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import {
88
} from '@microsoft/fast-foundation';
99
import { anchoredRegionStyles as styles } from './anchored-region.styles.js';
1010

11+
/**
12+
* Anchored region class
13+
*
14+
* @public
15+
* @tagname jp-anchored-region
16+
*/
17+
class JupyterAnchoredRegion extends AnchoredRegion {}
18+
1119
/**
1220
* A function that returns a {@link @microsoft/fast-foundation#AnchoredRegion} registration for configuring the component with a DesignSystem.
1321
* Implements {@link @microsoft/fast-foundation#anchoredRegionTemplate}
@@ -17,16 +25,13 @@ import { anchoredRegionStyles as styles } from './anchored-region.styles.js';
1725
* @remarks
1826
* Generates HTML Element: `<jp-anchored-region>`
1927
*/
20-
export const jpAnchoredRegion = AnchoredRegion.compose({
28+
export const jpAnchoredRegion = JupyterAnchoredRegion.compose({
2129
baseName: 'anchored-region',
30+
baseClass: AnchoredRegion,
2231
template,
2332
styles
2433
});
2534

26-
/**
27-
* Base class for AnchoredRegion
28-
* @public
29-
*/
30-
export { AnchoredRegion };
35+
export { JupyterAnchoredRegion as AnchoredRegion };
3136

3237
export { styles as anchoredRegionStyles };

packages/components/src/avatar/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
import { attr, html, when } from '@microsoft/fast-element';
66
import {
77
AvatarOptions,
8-
Avatar as FoundationAvatar,
8+
Avatar,
99
avatarTemplate as template
1010
} from '@microsoft/fast-foundation';
1111
import { avatarStyles as styles } from './avatar.styles.js';
1212

1313
/**
14-
* The Jupyter Avatar Class
15-
* @public
14+
* Jupyter Avatar Class
1615
*
16+
* @public
17+
* @tagname jp-avatar
1718
*/
18-
export class Avatar extends FoundationAvatar {
19+
class JupyterAvatar extends Avatar {
1920
/**
2021
* Indicates the Avatar should have an image source
2122
*
@@ -41,7 +42,7 @@ export class Avatar extends FoundationAvatar {
4142
* @public
4243
*
4344
*/
44-
export const imgTemplate = html<Avatar>`
45+
export const imgTemplate = html<JupyterAvatar>`
4546
${when(
4647
x => x.imgSrc,
4748
html`
@@ -65,9 +66,9 @@ export const imgTemplate = html<Avatar>`
6566
* @remarks
6667
* Generates HTML Element: `<jp-avatar>`
6768
*/
68-
export const jpAvatar = Avatar.compose<AvatarOptions>({
69+
export const jpAvatar = JupyterAvatar.compose<AvatarOptions>({
6970
baseName: 'avatar',
70-
baseClass: FoundationAvatar,
71+
baseClass: Avatar,
7172
template,
7273
styles,
7374
media: imgTemplate,
@@ -76,4 +77,6 @@ export const jpAvatar = Avatar.compose<AvatarOptions>({
7677
}
7778
});
7879

80+
export { JupyterAvatar as Avatar };
81+
7982
export { styles as avatarStyles };

packages/components/src/badge/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
import { Badge, badgeTemplate as template } from '@microsoft/fast-foundation';
66
import { badgeStyles as styles } from './badge.styles.js';
77

8+
/**
9+
* Badge class
10+
*
11+
* @public
12+
* @tagname jp-badge
13+
*/
14+
class JupyterBadge extends Badge {}
15+
816
/**
917
* A function that returns a {@link @microsoft/fast-foundation#Badge} registration for configuring the component with a DesignSystem.
1018
* Implements {@link @microsoft/fast-foundation#badgeTemplate}
@@ -14,16 +22,13 @@ import { badgeStyles as styles } from './badge.styles.js';
1422
* @remarks
1523
* Generates HTML Element: `<jp-badge>`
1624
*/
17-
export const jpBadge = Badge.compose({
25+
export const jpBadge = JupyterBadge.compose({
1826
baseName: 'badge',
27+
baseClass: Badge,
1928
template,
2029
styles
2130
});
2231

23-
/**
24-
* Base class for Badge
25-
* @public
26-
*/
27-
export { Badge };
32+
export { JupyterBadge as Badge };
2833

2934
export { styles as badgeStyles };

0 commit comments

Comments
 (0)