Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions example-project/component-library-react/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ export type MyButtonEvents = {
export const MyButton: StencilReactComponent<MyButtonElement, MyButtonEvents, Components.MyButton> = /*@__PURE__*/ createComponent<MyButtonElement, MyButtonEvents, Components.MyButton>({
tagName: 'my-button',
elementClass: MyButtonElement,
properties: {
color: 'color',
buttonType: 'button-type',
disabled: 'disabled',
expand: 'expand',
fill: 'fill',
download: 'download',
href: 'href',
rel: 'rel',
shape: 'shape',
size: 'size',
strong: 'strong',
target: 'target',
type: 'type'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -62,6 +77,21 @@ export type MyButtonScopedEvents = {
export const MyButtonScoped: StencilReactComponent<MyButtonScopedElement, MyButtonScopedEvents, Components.MyButtonScoped> = /*@__PURE__*/ createComponent<MyButtonScopedElement, MyButtonScopedEvents, Components.MyButtonScoped>({
tagName: 'my-button-scoped',
elementClass: MyButtonScopedElement,
properties: {
color: 'color',
buttonType: 'button-type',
disabled: 'disabled',
expand: 'expand',
fill: 'fill',
download: 'download',
href: 'href',
rel: 'rel',
shape: 'shape',
size: 'size',
strong: 'strong',
target: 'target',
type: 'type'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -82,6 +112,17 @@ export type MyCheckboxEvents = {
export const MyCheckbox: StencilReactComponent<MyCheckboxElement, MyCheckboxEvents, Components.MyCheckbox> = /*@__PURE__*/ createComponent<MyCheckboxElement, MyCheckboxEvents, Components.MyCheckbox>({
tagName: 'my-checkbox',
elementClass: MyCheckboxElement,
properties: {
color: 'color',
name: 'name',
checked: 'checked',
indeterminate: 'indeterminate',
disabled: 'disabled',
value: 'value',
labelPlacement: 'label-placement',
justify: 'justify',
alignment: 'alignment'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -99,6 +140,9 @@ export type MyComplexPropsEvents = NonNullable<unknown>;
export const MyComplexProps: StencilReactComponent<MyComplexPropsElement, MyComplexPropsEvents, Components.MyComplexProps> = /*@__PURE__*/ createComponent<MyComplexPropsElement, MyComplexPropsEvents, Components.MyComplexProps>({
tagName: 'my-complex-props',
elementClass: MyComplexPropsElement,
properties: {
grault: 'grault'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyComplexPropsEvents,
Expand All @@ -111,6 +155,9 @@ export type MyComplexPropsScopedEvents = NonNullable<unknown>;
export const MyComplexPropsScoped: StencilReactComponent<MyComplexPropsScopedElement, MyComplexPropsScopedEvents, Components.MyComplexPropsScoped> = /*@__PURE__*/ createComponent<MyComplexPropsScopedElement, MyComplexPropsScopedEvents, Components.MyComplexPropsScoped>({
tagName: 'my-complex-props-scoped',
elementClass: MyComplexPropsScopedElement,
properties: {
grault: 'grault'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyComplexPropsScopedEvents,
Expand All @@ -125,6 +172,11 @@ export type MyComponentEvents = {
export const MyComponent: StencilReactComponent<MyComponentElement, MyComponentEvents, Components.MyComponent> = /*@__PURE__*/ createComponent<MyComponentElement, MyComponentEvents, Components.MyComponent>({
tagName: 'my-component',
elementClass: MyComponentElement,
properties: {
first: 'first',
middleName: 'middle-name',
last: 'last'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -139,6 +191,7 @@ export type MyComponentDelegatesFocusEvents = NonNullable<unknown>;
export const MyComponentDelegatesFocus: StencilReactComponent<MyComponentDelegatesFocusElement, MyComponentDelegatesFocusEvents, Components.MyComponentDelegatesFocus> = /*@__PURE__*/ createComponent<MyComponentDelegatesFocusElement, MyComponentDelegatesFocusEvents, Components.MyComponentDelegatesFocus>({
tagName: 'my-component-delegates-focus',
elementClass: MyComponentDelegatesFocusElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyComponentDelegatesFocusEvents,
Expand All @@ -153,6 +206,11 @@ export type MyComponentScopedEvents = {
export const MyComponentScoped: StencilReactComponent<MyComponentScopedElement, MyComponentScopedEvents, Components.MyComponentScoped> = /*@__PURE__*/ createComponent<MyComponentScopedElement, MyComponentScopedEvents, Components.MyComponentScoped>({
tagName: 'my-component-scoped',
elementClass: MyComponentScopedElement,
properties: {
first: 'first',
middleName: 'middle-name',
last: 'last'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -169,6 +227,9 @@ export type MyCounterEvents = {
export const MyCounter: StencilReactComponent<MyCounterElement, MyCounterEvents, Components.MyCounter> = /*@__PURE__*/ createComponent<MyCounterElement, MyCounterEvents, Components.MyCounter>({
tagName: 'my-counter',
elementClass: MyCounterElement,
properties: {
startValue: 'start-value'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -188,6 +249,34 @@ export type MyInputEvents = {
export const MyInput: StencilReactComponent<MyInputElement, MyInputEvents, Components.MyInput> = /*@__PURE__*/ createComponent<MyInputElement, MyInputEvents, Components.MyInput>({
tagName: 'my-input',
elementClass: MyInputElement,
properties: {
color: 'color',
accept: 'accept',
autocapitalize: 'autocapitalize',
autocomplete: 'autocomplete',
autocorrect: 'autocorrect',
autofocus: 'autofocus',
clearInput: 'clear-input',
clearOnEdit: 'clear-on-edit',
disabled: 'disabled',
enterkeyhint: 'enterkeyhint',
inputmode: 'inputmode',
max: 'max',
maxlength: 'maxlength',
min: 'min',
minlength: 'minlength',
multiple: 'multiple',
name: 'name',
pattern: 'pattern',
placeholder: 'placeholder',
readonly: 'readonly',
required: 'required',
spellcheck: 'spellcheck',
step: 'step',
size: 'size',
type: 'type',
value: 'value'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -210,6 +299,34 @@ export type MyInputScopedEvents = {
export const MyInputScoped: StencilReactComponent<MyInputScopedElement, MyInputScopedEvents, Components.MyInputScoped> = /*@__PURE__*/ createComponent<MyInputScopedElement, MyInputScopedEvents, Components.MyInputScoped>({
tagName: 'my-input-scoped',
elementClass: MyInputScopedElement,
properties: {
color: 'color',
accept: 'accept',
autocapitalize: 'autocapitalize',
autocomplete: 'autocomplete',
autocorrect: 'autocorrect',
autofocus: 'autofocus',
clearInput: 'clear-input',
clearOnEdit: 'clear-on-edit',
disabled: 'disabled',
enterkeyhint: 'enterkeyhint',
inputmode: 'inputmode',
max: 'max',
maxlength: 'maxlength',
min: 'min',
minlength: 'minlength',
multiple: 'multiple',
name: 'name',
pattern: 'pattern',
placeholder: 'placeholder',
readonly: 'readonly',
required: 'required',
spellcheck: 'spellcheck',
step: 'step',
size: 'size',
type: 'type',
value: 'value'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -227,6 +344,7 @@ export type MyListEvents = NonNullable<unknown>;
export const MyList: StencilReactComponent<MyListElement, MyListEvents, Components.MyList> = /*@__PURE__*/ createComponent<MyListElement, MyListEvents, Components.MyList>({
tagName: 'my-list',
elementClass: MyListElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyListEvents,
Expand All @@ -239,6 +357,7 @@ export type MyListItemEvents = NonNullable<unknown>;
export const MyListItem: StencilReactComponent<MyListItemElement, MyListItemEvents, Components.MyListItem> = /*@__PURE__*/ createComponent<MyListItemElement, MyListItemEvents, Components.MyListItem>({
tagName: 'my-list-item',
elementClass: MyListItemElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyListItemEvents,
Expand All @@ -251,6 +370,7 @@ export type MyListItemScopedEvents = NonNullable<unknown>;
export const MyListItemScoped: StencilReactComponent<MyListItemScopedElement, MyListItemScopedEvents, Components.MyListItemScoped> = /*@__PURE__*/ createComponent<MyListItemScopedElement, MyListItemScopedEvents, Components.MyListItemScoped>({
tagName: 'my-list-item-scoped',
elementClass: MyListItemScopedElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyListItemScopedEvents,
Expand All @@ -263,6 +383,7 @@ export type MyListScopedEvents = NonNullable<unknown>;
export const MyListScoped: StencilReactComponent<MyListScopedElement, MyListScopedEvents, Components.MyListScoped> = /*@__PURE__*/ createComponent<MyListScopedElement, MyListScopedEvents, Components.MyListScoped>({
tagName: 'my-list-scoped',
elementClass: MyListScopedElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyListScopedEvents,
Expand All @@ -280,6 +401,16 @@ export type MyPopoverEvents = {
export const MyPopover: StencilReactComponent<MyPopoverElement, MyPopoverEvents, Components.MyPopover, 'component'> = /*@__PURE__*/ createComponent<MyPopoverElement, MyPopoverEvents, Components.MyPopover, 'component'>({
tagName: 'my-popover',
elementClass: MyPopoverElement,
properties: {
component: 'component',
keyboardClose: 'keyboard-close',
cssClass: 'css-class',
backdropDismiss: 'backdrop-dismiss',
event: 'event',
showBackdrop: 'show-backdrop',
translucent: 'translucent',
animated: 'animated'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -300,6 +431,15 @@ export type MyRadioEvents = {
export const MyRadio: StencilReactComponent<MyRadioElement, MyRadioEvents, Components.MyRadio> = /*@__PURE__*/ createComponent<MyRadioElement, MyRadioEvents, Components.MyRadio>({
tagName: 'my-radio',
elementClass: MyRadioElement,
properties: {
color: 'color',
name: 'name',
disabled: 'disabled',
value: 'value',
labelPlacement: 'label-placement',
justify: 'justify',
alignment: 'alignment'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -317,6 +457,12 @@ export type MyRadioGroupEvents = {
export const MyRadioGroup: StencilReactComponent<MyRadioGroupElement, MyRadioGroupEvents, Components.MyRadioGroup> = /*@__PURE__*/ createComponent<MyRadioGroupElement, MyRadioGroupEvents, Components.MyRadioGroup>({
tagName: 'my-radio-group',
elementClass: MyRadioGroupElement,
properties: {
allowEmptySelection: 'allow-empty-selection',
compareWith: 'compare-with',
name: 'name',
value: 'value'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -335,6 +481,20 @@ export type MyRangeEvents = {
export const MyRange: StencilReactComponent<MyRangeElement, MyRangeEvents, Components.MyRange> = /*@__PURE__*/ createComponent<MyRangeElement, MyRangeEvents, Components.MyRange>({
tagName: 'my-range',
elementClass: MyRangeElement,
properties: {
color: 'color',
debounce: 'debounce',
name: 'name',
dualKnobs: 'dual-knobs',
min: 'min',
max: 'max',
pin: 'pin',
snaps: 'snaps',
step: 'step',
ticks: 'ticks',
disabled: 'disabled',
value: 'value'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand All @@ -351,6 +511,7 @@ export type MyToggleEvents = NonNullable<unknown>;
export const MyToggle: StencilReactComponent<MyToggleElement, MyToggleEvents, Components.MyToggle> = /*@__PURE__*/ createComponent<MyToggleElement, MyToggleEvents, Components.MyToggle>({
tagName: 'my-toggle',
elementClass: MyToggleElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyToggleEvents,
Expand All @@ -363,6 +524,9 @@ export type MyToggleContentEvents = NonNullable<unknown>;
export const MyToggleContent: StencilReactComponent<MyToggleContentElement, MyToggleContentEvents, Components.MyToggleContent> = /*@__PURE__*/ createComponent<MyToggleContentElement, MyToggleContentEvents, Components.MyToggleContent>({
tagName: 'my-toggle-content',
elementClass: MyToggleContentElement,
properties: {
visible: 'visible'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyToggleContentEvents,
Expand All @@ -375,6 +539,9 @@ export type MyTransformTestEvents = NonNullable<unknown>;
export const MyTransformTest: StencilReactComponent<MyTransformTestElement, MyTransformTestEvents, Components.MyTransformTest> = /*@__PURE__*/ createComponent<MyTransformTestElement, MyTransformTestEvents, Components.MyTransformTest>({
tagName: 'my-transform-test',
elementClass: MyTransformTestElement,
properties: {
message: 'message'
},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyTransformTestEvents,
Expand Down
6 changes: 6 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ npm install typescript@5 --save-dev

That's it! You can now import and use your Stencil components as React components in your React application or library.

### Server-side rendering

When a wrapper is rendered on the server (Next.js, Remix, Vite SSR), it emits the component's props as attributes on the host tag, for example `<my-button variant="outline">`. The element then upgrades in its final state on the client instead of flashing its defaults until React hydrates.

This covers host attributes only. Shadow DOM and styles are still created in the browser. To render the full component on the server, use the `hydrateModule` option (see below) or [@stencil/ssr](https://github.com/stenciljs/output-targets/tree/main/packages/ssr).

## Output Target Options

| Property | Description |
Expand Down
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@types/node": "^20.19.43",
"@types/react": "^19.2.17",
"@types/react-dom": "^19.2.3",
"jsdom": "^26.1.0",
"npm-run-all2": "^6.2.6",
"stencil-output-targets-shared": "workspace:*",
"ts-dedent": "^2.3.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/create-component-wrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type MyComponentEvents = NonNullable<unknown>;
export const MyComponent: StencilReactComponent<MyComponentElement, MyComponentEvents, Components.MyComponent> = /*@__PURE__*/ createComponent<MyComponentElement, MyComponentEvents, Components.MyComponent>({
tagName: 'my-component',
elementClass: MyComponentElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyComponentEvents,
Expand Down Expand Up @@ -115,6 +116,7 @@ export type MyComponentEvents = NonNullable<unknown>;
export const MyComponent: StencilReactComponent<MyComponentElement, MyComponentEvents, Components.MyComponent> = /*@__PURE__*/ createComponent<MyComponentElement, MyComponentEvents, Components.MyComponent>({
tagName: 'my-component',
elementClass: MyComponentElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyComponentEvents,
Expand Down Expand Up @@ -226,6 +228,7 @@ export type MyComponentEvents = {
export const MyComponent: StencilReactComponent<MyComponentElement, MyComponentEvents, Components.MyComponent> = /*@__PURE__*/ createComponent<MyComponentElement, MyComponentEvents, Components.MyComponent>({
tagName: 'my-component',
elementClass: MyComponentElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('createStencilReactComponents', () => {
.toContain(`export const MyComponent: StencilReactComponent<MyComponentElement, MyComponentEvents, Components.MyComponent> = /*@__PURE__*/ createComponent<MyComponentElement, MyComponentEvents, Components.MyComponent>({
tagName: 'my-component',
elementClass: MyComponentElement,
properties: {},
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
react: React,
events: {} as MyComponentEvents,
Expand Down
Loading
Loading