Skip to content

feat: add @tutorialkit/theme package to use the theme without astro #105

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

Merged
merged 7 commits into from
Jun 28, 2024

Conversation

Nemikolh
Copy link
Member

While trying to use TutorialKit's React components in isolation, I noticed that they depend on the theme constants. While most users will probably want to provide their own config there to fully tweak them, being able to access default is going to be really useful.

Thus the @tutorialkit/theme package. Maybe we should name it @tutorialkit/unocss-theme? Curious to hear opinions here, @d3lm, @AriPerkkio and @SamVerschueren.

Furthermore, right now if we needed to update the shortcuts or the rules we couldn't because they are in the uno.config.ts file of the template. So once someone has created a tutorial they are stuck with their values unless they update them. By exposing them from this package we can now update them (for future tutorials at least).

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

cloudflare-workers-and-pages bot commented Jun 28, 2024

Deploying tutorialkit-demo-page with  Cloudflare Pages  Cloudflare Pages

Latest commit: a5af49c
Status: ✅  Deploy successful!
Preview URL: https://8346ffcf.tutorialkit-demo-page.pages.dev
Branch Preview URL: https://joan-unocss-theme-pkg.tutorialkit-demo-page.pages.dev

View logs

@@ -322,4 +322,4 @@ export const theme: ConfigBase['theme'] = {
},
},
},
};
} satisfies ConfigBase['theme'];
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'm using a satisfies here so that they can import the theme and then override values and have autocompletion.

@Nemikolh Nemikolh requested a review from HeyGarrison June 28, 2024 14:04
Copy link
Contributor

@d3lm d3lm left a comment

Choose a reason for hiding this comment

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

LGTM 👍 🔥

Personally I am fine with @tutorialkit/theme.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit risky to expose these cause it's a contract that the components rely on for the layout. But I guess if someone would change these they'd be own their own so it's on them if they break it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I agree, I honestly don't know what the best approach would be. I looked at how material ui does it:

They have a https://github.com/mui/material-ui/blob/v5.15.20/packages/mui-material/src/Button/buttonClasses.ts file which generate a bunch of class names and they don't do anything with it. But I think it lets you tweak the component entirely from CSS?

However it seems that you can also customize it via JavaScript when you look at this: https://github.com/mui/material-ui/blob/v5.15.20/packages/mui-material/src/Button/Button.js#L100-L119:

        backgroundColor: theme.vars
          ? `rgba(${theme.vars.palette.text.primaryChannel} / ${theme.vars.palette.action.hoverOpacity})`
          : alpha(theme.palette.text.primary, theme.palette.action.hoverOpacity),
        // Reset on touch devices, it doesn't add specificity
        '@media (hover: none)': {
          backgroundColor: 'transparent',
        },
        ...(ownerState.variant === 'text' &&
          ownerState.color !== 'inherit' && {
            backgroundColor: theme.vars
              ? `rgba(${theme.vars.palette[ownerState.color].mainChannel} / ${
                  theme.vars.palette.action.hoverOpacity
                })`
              : alpha(theme.palette[ownerState.color].main, theme.palette.action.hoverOpacity),
            // Reset on touch devices, it doesn't add specificity
            '@media (hover: none)': {
              backgroundColor: 'transparent',
            },
          }),

But they also have hardcoded values in a few places, like https://github.com/mui/material-ui/blob/v5.15.20/packages/mui-material/src/Button/Button.js#L90 :

      padding: '6px 16px',

@Nemikolh Nemikolh requested review from d3lm and AriPerkkio June 28, 2024 14:50
@Nemikolh Nemikolh merged commit 9805996 into main Jun 28, 2024
8 checks passed
@Nemikolh Nemikolh deleted the joan/unocss-theme-pkg branch June 28, 2024 20:35
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

@Nemikolh I think this broke freshly generated tutorials:

  • pnpm install; pnpm build
  • Run node ./packages/cli/dist/index.js create and create new project. I used npm as package manager but might reproduce on others as well
  • cd <new tutorial>
  • npm install; npm run dev
  • Error below shows:

image

To narrow dow the root cause to this specific PR, checkout to earlier d8a5a341df6c2d23d1d59ede61b4d3ef689af081 and repeat the steps. Everything works fine.

In future we'll have integration tests to prevent this kind of issues! 😄

@Nemikolh
Copy link
Member Author

Nemikolh commented Jul 2, 2024

@AriPerkkio Ah this error is actually expected!

This is only an error now because this PR introduced a breaking changes and the updateWorkspaceVersion replace the packages with older versions that are here incompatible.

So hopefully integration tests won't error on this kind of changes. If you ran into an issue with them I think it's a bug.

@AriPerkkio
Copy link
Member

Oh right, it's trying to use unreleased APIs from the older version of the package. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants