Navigation Menu

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

spike: Example of custom button through intercept #2848

Closed
wants to merge 4 commits into from

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Nov 4, 2020

Just a spike to try out one approach to themes through the scaffolded intercept file.

The intercept file replaces all instances of Button with the CustomButton component which is identical except for a dynamic load of the css used. When store_code is fr, it loads frenchButton.css and uses those classes instead of the default.

Try it out by switching the store to "French Store View".

Image from Gyazo

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Nov 4, 2020

Fails
🚫 Missing "Description" section. Please add it back, with detail.
🚫 Missing "Verification Steps" section. Please add it back, with detail.
🚫

No linked issue found. Please link a relevant open issue by adding the text "closes #<issue_number>" or "closes JIRA-<issue_number>" in your PR.

🚫

Unable to build scaffolded project.

yarn build

within a scaffolded project directory failed.
Learn more about Scaffolding at https://magento.github.io/pwa-studio/pwa-buildpack/scaffolding/.

🚫 A version label is required. A maintainer must add one.
🚫

node` failed.

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

If your PR is missing information, check against the original template here. At a minimum you must have the section headers from the template and provide some information in each section.

Log

ERROR ON TASK: scaffoldingSucceeds


Error:  Danger had errors running. See message(s) above for more details.
danger-results://tmp/danger-results.json

Generated by 🚫 dangerJS against cafee5d

Signed-off-by: sirugh <rugh@adobe.com>
@sirugh sirugh force-pushed the rugh/spike-theme-via-local-intercept branch from 8c736a6 to 5f75e4b Compare November 4, 2020 21:51
Signed-off-by: sirugh <rugh@adobe.com>
);
button.replaceJSX(
'button',
`<${CustomButton} className={rootClassName} type={type} disabled={disabled} {...restProps}>{children}</${CustomButton}>`
Copy link
Contributor Author

@sirugh sirugh Nov 5, 2020

Choose a reason for hiding this comment

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

Preferably we would just overwrite the export of the Button component with the CustomButton rather than replacing the JSX which requires knowledge of the props/children structure.

@jimbo suggested:

// before
export { default } from "./button"
// after
export { default } from "@magento/venia-concept/src/components/CustomButton"

@sirugh sirugh force-pushed the rugh/spike-theme-via-local-intercept branch from 93f1c46 to 456a831 Compare November 5, 2020 18:45
Comment on lines 25 to 30
const storeCode = storage.getItem('store_view_code');
const [css, setCss] = useState(defaultClasses);
useEffect(() => {
if (storeCode === 'fr') {
loadCss();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how I feel about components having an understanding of the store view code. I wonder if there'd be some mechanism of doing this at a framework level so we don't end up with store view codes in components. Just food for thought :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would you know which css to load for which store code? Something will have to know, right? Also, this "CustomButton" is a custom component from the client, not built into PWA Studio. You can only do such extension through scaffolding so it's in venia-concept as an example.

Copy link
Contributor

Choose a reason for hiding this comment

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

It really depends what we refer to when we say theming, this could mean changing one or two components, changing some CSS, or having a completely different tree of components with inheritance.

Would be good to validate legitimate business cases of theme customization and see where they align.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, the point of this spike PR was just to explore dynamic CSS loading. My take is that customization and theming are going to continue to fall into the realm of our developer users. The extension framework allows for so much customization and granularity that it seems counter productive to implement some rigid structure around what we consider theming.

Anyways, I agree that we need to understand the business cases before implementing anything concrete. I've written up my thoughts in the JIRA ticket.

Signed-off-by: sirugh <rugh@adobe.com>
Comment on lines +1 to +4
.root {
color: red;
border-color: red;
}
Copy link
Contributor Author

@sirugh sirugh Nov 5, 2020

Choose a reason for hiding this comment

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

My intent was just for this to be the css that was needed. Should be possible to provide just those overrides without having to know all the rest of the classes.

<button
// The only other custom thing here...But there might be a better
// way to ensure that incoming classes are used.
className={`${className} ${rootClassName}`}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be preferable to just modify the Button component itself with this and the changes from line 25. No copy of Button would be necessary, just need to import the hook and pass it the component name + default classes.

@sirugh
Copy link
Contributor Author

sirugh commented Nov 6, 2020

Closing this as I have explored the idea enough.

@sirugh sirugh closed this Nov 6, 2020
@sirugh sirugh deleted the rugh/spike-theme-via-local-intercept branch November 6, 2020 01:01
@m2-community-project m2-community-project bot removed this from Review in Progress in Pull Request Progress Nov 6, 2020
@sirugh sirugh restored the rugh/spike-theme-via-local-intercept branch April 26, 2021 16:27
@sirugh sirugh deleted the rugh/spike-theme-via-local-intercept branch April 26, 2021 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants