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

Proposal/RFC for custom tag names #538

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"no-duplicate-selectors": null,
"rule-empty-line-before": null,
"selector-class-pattern": null,
"selector-type-no-unknown": [
true,
{
"ignore": ["custom-elements"]
}
],
"value-keyword-case": null
}
}
13 changes: 3 additions & 10 deletions js/src/components/content-button-layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
*/
import './index.scss';

const ContentButtonLayout = ( props ) => {
const { className, ...rest } = props;

return (
<div
className={ `gla-content-button-layout ${ className }` }
{ ...rest }
/>
);
};
const ContentButtonLayout = ( props ) => (
<woo-gla-content-button-layout { ...props } />
Copy link
Member

@ecgan ecgan May 5, 2021

Choose a reason for hiding this comment

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

I'm hoping / expecting this would work well with (possible future) CSS-in-JS solution, e.g. with emotion library (prior research: #71 ):

<woo-gla-content-button-layout
    className={css`
      padding: 32px;
      background-color: hotpink;
      font-size: 24px;
      border-radius: 4px;
      &:hover {
        color: ${color};
      }
    `}
  >

That would be great 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't tried it with emotion. but I guess if emotion works for other elements div, p, span.

<div
    className={css`
      padding: 32px;
      background-color: hotpink;
      font-size: 24px;
      border-radius: 4px;
      &:hover {
        color: ${color};
      }
    `}
  >

I see no reason why it should work for all HTML elements.

For sure it works with native CSS-in-JS solution, like #539

Comment on lines +6 to +7
Copy link
Member

Choose a reason for hiding this comment

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

One common confusion is that Web Components use “class” instead of “className”.
- Quoted from https://reactjs.org/docs/web-components.html#using-web-components-in-react

Not sure if there is an easier way supported by react API to transform className to class, or we would need a helper like:

const cx = ( props ) => {
	if ( props.hasOwnProperty( 'className' ) ) {
		const { className, ...restProps } = props;
		return { class: className, ...restProps };
	}
	return props;
};

<woo-gla-content-button-layout { ...cx( props ) } />

Copy link
Member Author

@tomalec tomalec May 6, 2021

Choose a reason for hiding this comment

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

Thanks for catching this. Definitely, that's something we should be cautious about.

The thing is, we are not using Web Components here. woo-gla-content-button-layout is not a custom element. (it's a valid custom element name, but it's not customElements.define)

Therefore, I find it really strange that React does translate className to class for div, span etc, but not for any-other-element. Probably, that's and effect of simple check for custom-elements, and React's strategy for real custom elements facebook/react#4933, facebook/react#7901

That means if we would have to attach React event listeners to <woo-gla-content-button-layout> we would have to translate them as well.

Luckily, the children's elements are unaffected. So if we are about to cater only for a dummy <div className='gla-content-button-layout'> CSS layout wrapper, we're safe.


We can also try

const ContentButtonLayout = ( props ) => (
	<wooglacontentbuttonlayout { ...props } />
);

Screenshoot of the above in dev tools

Then it's obvious that it's not a custom element. Then we do not need to open the "React vs. Web Standards" can of worms.
The only formal disadvantage of that, it does not pass HTML validation, even though the behavior is pretty reliable: https://stackoverflow.com/questions/10830682/is-it-ok-to-use-unknown-html-tags/27869027#27869027

);

export default ContentButtonLayout;
Comment on lines 3 to 10
Copy link
Member

Choose a reason for hiding this comment

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

I got to say I like this, from 17 lines to 10 lines (and potentially even more for files that have imported and used classnames)! Really simplified a lot! ❤️

2 changes: 1 addition & 1 deletion js/src/components/content-button-layout/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.gla-content-button-layout {
woo-gla-content-button-layout {
display: flex;
justify-content: space-between;
align-items: center;
Expand Down