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

Sample extensions for different styling methods #7

Merged
merged 9 commits into from
Nov 20, 2020

Conversation

aleksfront
Copy link
Contributor

Adding 3 sample extensions for different styling modifications. All of them based on HelloWorld sample.

  • styling-sass-sample extension using Sass
  • styling-emotion-sample extension using CSS-in-JS Emotion
  • styling-css-modules-sample extension using CSS Modules for class name encapsulation

styling samples

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
@aleksfront aleksfront requested review from nevalla, jakolehm, ixrock and a team and removed request for nevalla, jakolehm and ixrock November 12, 2020 12:56
export default class ModulesStylingExtension extends LensRendererExtension {
clusterPages = [
{
path: "/css-modules-styling-sample",
Copy link

@ixrock ixrock Nov 13, 2020

Choose a reason for hiding this comment

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

API is changed, now page-registration and page-menu-regisration are splitted.
Working example:

  clusterPages = [
    {
      id: "example-page-id",
      components: {
        Page: () => <ExamplePage extension={this}/>,
      }
    }
  ]

  clusterPageMenus = [
    {
      id: this.clusterPages[0].id, // must be the same as in page registration to be visible in sidebar
      title: "Hello World",
      components: {
        Icon: ExampleIcon
      }
    }
  ]

Copy link
Contributor Author

@aleksfront aleksfront Nov 13, 2020

Choose a reason for hiding this comment

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

Starting the app with described changes and got

Uncaught TypeError: Expected "name" to match "[^\/#\?]+?", but got "@k8slens/styling-css-modules-sample"
    at LensDev.js:402426
    at n.getPageUrl (LensDev.js:521110)
    at LensDev.js:523074
    at Array.map (<anonymous>)
    at PageMenuRegistry.getItems (LensDev.js:523073)
    at Sidebar.render (LensDev.js:636929)
    at allowStateChanges (LensDev.js:334943)
    at LensDev.js:333372
    at trackDerivedFunction (LensDev.js:334726)
    at Reaction../node_modules/mobx/lib/mobx.module.js.Reaction.track (LensDev.js:335760)

with app crash. Something with id?

Copy link

Choose a reason for hiding this comment

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

Upgrade to:

"@k8slens/extensions": "^4.0.0-beta.1",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a url doesn't help either:

clusterPages = [
    {
      id: "extension-example",
      components: {
        Page: () => <ExamplePage extension={this}/>,
      }
    }
  ]

  clusterPageMenus = [
    {
      id: this.clusterPages[0].id, // must be the same as in page registration to be visible in sidebar
      url: `/${this.clusterPages[0].id}`,
      title: "Hello World",
      components: {
        Icon: ExampleIcon
      }
    }
  ]

Copy link

Choose a reason for hiding this comment

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

Ok, probably better to wait fixes from lensapp/lens#1364

"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"jsx": "react",
"plugins": [{ "name": "typescript-plugin-css-modules" }],
Copy link

Choose a reason for hiding this comment

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

Did't know about that field. How does it work? Where the list of available plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the plugin field documentation https://www.typescriptlang.org/tsconfig#plugins
And here is typescript-plugin-css-modules page https://github.com/mrmckeb/typescript-plugin-css-modules

padding: calc(var(--padding) * 2);

// Check if light theme enabled in Lens
.theme-light & {
Copy link

Choose a reason for hiding this comment

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

probably we should specify top-level theme element more precisely, like body[data-theme="light"]

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'm working on this, changes will be in different PR.

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
@stefcameron
Copy link

@aleksfront I had a quick look. It's great that you're providing these samples, thank you! What I don't see is the theme switching use case. How will developers handle that? How will they know when the theme changes? Right now, all I see are different ways to write CSS that uses theme-based CSS variables -- but maybe I missed something since I didn't look closely at everything.

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
@aleksfront
Copy link
Contributor Author

@ixrock Samples working with latest (beta 3) extension api types. Please re-review.
styling extensions

@aleksfront aleksfront merged commit cee0c20 into master Nov 20, 2020
@aleksfront aleksfront deleted the styling-examples branch November 20, 2020 10:12
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