8000 [DISCUSSION] Dynamic loading style (CSS) and theming support · Issue #340 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

[DISCUSSION] Dynamic loading style (CSS) and theming support #340

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

Closed
fpliger opened this issue May 11, 2022 · 10 comments
Closed

[DISCUSSION] Dynamic loading style (CSS) and theming support #340

fpliger opened this issue May 11, 2022 · 10 comments
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release ideas Ideas worth exploring lang: typescript Related to the Typescript language tag: styling Related to the styling of pyscript components type: feature New feature or request

Comments

@fpliger
Copy link
Contributor
fpliger commented May 11, 2022

PyScript currently "requires" users to load the CSS explicitly and separately from the JS. This has a few limitations:

  • locks the flexibility of customizing style
  • forces to load all the styles before the JS logic itself (adding up to the loading time, even if just a little)
  • not friendly to support theming
  • users have to specify 2 cmds to load PyScript on their pages (link to CSS and script to js)

If we switch to lading CSS dynamically within the scope of pyscript.js we can:

  • have a default global style that loads if not stylesheet or theme has been specified
  • allow users to create stylesheets/themes on their own that can be used instead of the default one
  • have more control over what's being loaded into the page and when
  • reduce the amounts of steps needed for a user to start using PyScript

In terms of implementation, we could allow users to specify a theme for the app in the AppConfig yaml that can be loaded in runtime.

Would love to hear opinions about the good and bad of the different approaches and possible alternative solutions. :)

@fpliger fpliger added type: feature New feature or request tag: styling Related to the styling of pyscript components ideas Ideas worth exploring lang: typescript Related to the Typescript language labels May 11, 2022
@j16h
Copy link
Contributor
j16h commented May 11, 2022

Framework-agnostic CSS-in-JS libraries (see JSS) can help us to load CSS dynamically and address some of the concerns you've mentioned above.

imho. for theming configuration, I'd suggest sticking to JS "world" practices and allowing defining themes in *.js, rather than in yaml. JSS should already address that as well.

@fpliger
Copy link
Contributor Author
fpliger commented May 11, 2022

Thanks for the suggestion. Yeah, sticking with best practices as much as possible is definitely a good principle we should try to stick with.

From your comment, I also realized that my proposal wasn't well explained on my part. I'm not suggesting that we add the style rules and all in the yaml itself but use the yaml to provide pyscript the metadata to access the theme somewhere (so it can also load its related assets), with a name/location/url.

@verhulstm
Copy link
Contributor

i would like to support simple pure css themes. i do also like the idea of supporting CSS-in-JS like JSS. so i would like both.

many beginners will want to dig into learning python and web tech, and making or modifying a theme is a good starting point for a ton of folks. JSS is too complex for some who are just starting out in their learning. for them, i want to be able to point to a simple pure css theme as a starting point. and then they can move on to JSS

@j16h
Copy link
Contributor
j16h commented May 13, 2022

@verhulstm agree. For that, we could provide a user-friendly API to do theming. We can still leverage JSS-like frameworks and wrap it with a simple API. Here is a simple example of what it might look like.

We introduce a provider component that would wrap the other components and propagate styles/themes to other components used in the Pyscript.

We expose the configuration that is easy to reason about for novice users, as well as support more complex configurations for more advanced users.

Define theme:

const customTheme = extendTheme({
    semanticTokens: {
        colors: {
            error: 'red.500',
            success: 'green.500',
            primary: {
                default: 'red.500',
                _dark: 'red.400',
            },
            secondary: {
                default: 'red.800',
                _dark: 'red.700',
            },
        },
        components: {
            'py-button': {
                backgroundColor: 'black.500',
                color: 'white.200'
            },
            'py-title': {
                color: 'yellow.500',
                fontSize: '14px',
            },
            'py-input-box': {
                color: 'black.200',
                fontSize: '14px'
            },
        },
    },
})

Theme usage:

<py-provider theme={customTheme}>
  ....
  <py-title></py-title>
  <py-inputbox><py-inputbox>
  <py-button></py-button>
<py-provider/>

@verhulstm
Copy link
Contributor

can we support all the above in a css file?

@pauleveritt
Copy link

+1 for pure CSS as an option. Peter quite rightly bangs the drum about entry, that <script type="text/python"> is too much typing vs. <py-script>. Same applies to "you have to do npm install and learn a JSS framework, produce a build, etc.".

Frankly, I hope PyScript splits and doesn't mandate any CSS, as you won't choose what I want (Bulma). Something built atop should be opinionated. My two cents.

@fpliger
Copy link
Contributor Author
fpliger commented May 17, 2022

This is a great discussion.

I get the point about not mandating CSS and keeping PyScript as lean as possible, otoh, if we really want to target non-technical users to empower them with easy to build UI capabilities, we do need to have an opinonated options for them to just drop new components on a page "that just works".

With that said, I think this can be optional. Either by loading the theme (CSS) as an option or vice versa (basically opt-in vs opt-out). Or even splitting theming from PyScript core and let it be a separate load (this would mean that users need to do extra work though, that is harder for non-technical users).

@pauleveritt
Copy link

I'm working on a video that talks about a core/app split, FWIW. Most people would consume the app. But if someone wanted to make a new pluggable app -- e.g. Minecraft -- they could make their own decisions on CSS, 8000 CSS/JS framework, etc.

I realize it's just my opinion, but I should speak with a demo, rather than ticket comments. 😀

@fpliger
Copy link
Contributor Author
fpliger commented May 17, 2022

That sounds great. Yeah, demos are more effective than words, for sure! 😄

@marimeireles
Copy link
Contributor

I guess this is very related to this issue: #78
I'm gonna centralize the discussion here, but ^ 78 is relevant for it :)

@marimeireles marimeireles added the backlog issue has been triaged but has not been earmarked for any upcoming release label Oct 4, 2022
@pyscript pyscript locked and limited conversation to collaborators Feb 12, 2023
@marimeireles marimeireles converted this issue into discussion #1172 Feb 12, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
backlog issue has been triaged but has not been earmarked for any upcoming release ideas Ideas worth exploring lang: typescript Related to the Typescript language tag: styling Related to the styling of pyscript components type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants
0