Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web-components: Fix custom-elements order of property application #19183

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Object {
},
},
"type": Object {
"name": "void",
"name": "boolean",
},
},
"backSide": Object {
Expand Down Expand Up @@ -126,7 +126,7 @@ Object {
"name": "header",
"required": false,
"table": Object {
"category": "properties",
"category": "attributes",
"defaultValue": Object {
"summary": "\\"Your Message\\"",
},
Expand All @@ -152,7 +152,7 @@ Object {
"name": "rows",
"required": false,
"table": Object {
"category": "properties",
"category": "attributes",
"defaultValue": Object {
"summary": "[]",
},
Expand Down
17 changes: 14 additions & 3 deletions code/renderers/web-components/src/docs/custom-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@ interface Declaration {
}

function mapItem(item: TagItem, category: string): InputType {
const type =
category === 'properties' ? { name: item.type?.text || item.type } : { name: 'void' };
let type;
switch (category) {
case 'attributes':
case 'properties':
type = { name: item.type?.text || item.type };
break;
case 'slots':
type = { name: 'string' };
break;
default:
type = { name: 'void' };
break;
}
Copy link
Contributor

@usrrname usrrname Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, and sorely needed! I'd contemplate bringing this into @storybook/html as well re: transformation of attributes as opposed to properties to args. I say this because it's an easy conflation to newcomers and having a way to distinguish these... would make onboarding to WC DS much easier.


return {
name: item.name,
Expand Down Expand Up @@ -137,9 +148,9 @@ export const extractArgTypesFromElements = (tagName: string, customElements: Cus
const metaData = getMetaData(tagName, customElements);
return (
metaData && {
...mapData(metaData.attributes, 'attributes'),
...mapData(metaData.members, 'properties'),
...mapData(metaData.properties, 'properties'),
...mapData(metaData.attributes, 'attributes'),
...mapData(metaData.events, 'events'),
...mapData(metaData.slots, 'slots'),
...mapData(metaData.cssProperties, 'css custom properties'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
],
"slots": [
{
"description": "This is an unnamed slot (the default slot)",
"name": ""
"name": "prefix",
"description": "Label prefix"
}
],
"members": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import './demo-wc-card';

export default {
component: 'demo-wc-card',
render: ({ backSide, header, rows, prefix }) =>
html`
<demo-wc-card .backSide="${backSide}" .header="${header}" .rows="${rows}"
><span slot="prefix">${prefix}</span>A simple card</demo-wc-card
>
`,
};

const Template = ({ backSide, header, rows }) =>
html`
<demo-wc-card .backSide="${backSide}" .header="${header}" .rows="${rows}"
>A simple card</demo-wc-card
>
`;
export const Front = {
args: { backSide: false, header: undefined, rows: [] },
};

export const Back = {
args: { backSide: true, header: undefined, rows: [] },
};

export const Front = Template.bind({});
Front.args = { backSide: false, header: undefined, rows: [] };
export const Prefix = {
args: { backSide: false, prefix: 'prefix:', header: 'my header', rows: [] },
};
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class DemoWcCard extends LitElement {
</div>
</div>
<div id="back" part="back">
<div class="header">${this.header}</div>
<div class="header"><slot name="prefix"></slot> ${this.header}</div>

<div class="content">
${this.rows.length === 0
Expand Down