-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Docs: extension styling and theming #1267
Conversation
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start at documentation for styles! It'll be very helpful, I'm sure. I learned about flex.box
thanks to this; I knew there was some kind of library being used for flexbox in Lens, but didn't know what it was. Now at least I know what some styles available to me are.
My feedback in comments...
@@ -0,0 +1,104 @@ | |||
# Styling | |||
Lens provides a set of global styles and UI components that can be used by any extension to preserve look and feel of the application. However, it’s always up to the developer whether to use them or provide completely different styles for the extension. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can only make this claim
However, it’s always up to the developer whether to use them or provide completely different styles for the extension.
if you have fixed #1251
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed for now
If you want to follow a selected theme to keep the 'native' Lens look and feel, respecting the light/dark appearance of your extension, you can use provided variables and build-in lens components such as buttons, dropdowns, checkboxes etc. | ||
|
||
## Injected styles | ||
Every extention is affected by list of default global styles defined in `src/renderer/components/app.scss`. These are basic browser resets like setting `box-sizing` property for every element, default text and background colors, default font size, basic headings visualisation etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the stuff I think extensions should be isolated from (including flex.box
as mentioned earlier) as part of #1251. Overriding these to reset them would be quite a challenge. I realize that's separate from this issue.
For now, this paragraph is very useful, since it states the current behavior, and points users to the Lens code that defines all the styles.
### vars.scss | ||
In `src/renderer/components/vars.scss` there are list of predefined variables mostly for dimensions and fonts. | ||
``` | ||
// Dimensions | ||
$unit: 8px; | ||
$padding: $unit; | ||
$margin: $unit; | ||
$radius: ceil($unit * .3); | ||
|
||
// Fonts | ||
$font-main: 'Roboto', 'Helvetica', 'Arial', sans-serif !default; | ||
$font-monospace: Lucida Console, Monaco, Consolas, monospace; | ||
$font-size-small: floor(1.5 * $unit); | ||
$font-size: floor(1.75 * $unit); | ||
$font-size-big: floor(2 * $unit); | ||
$font-weight-thin: 300; | ||
$font-weight-normal: 400; | ||
$font-weight-bold: 500; | ||
... | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to know. #1251 should move all these into CSS variables to make them more accessible, like the colors are, regardless of using SCSS or not.
I'm also not sure how an extension would reference this SCSS file. It's not published in the @k8slens/extensions
package...
Having the file reference is useful, but without being able to reference it in the extension's SCSS build, not very useful at all. If they were CSS variables, that would be a different story...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted all of these into CSS vars.
### theme-vars.scss | ||
In `src/renderer/themes/theme-vars.scss` there are list of theme-defined colors. Most of their values are different for light and dark themes. You can use them to preserve consitent view of extension with respect of selected theme. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: How would I reference this in an extension's build? These all reference CSS vars, so that's much better (more accessible to a wider range of extension implementations; my extension doesn't use SCSS, BTW, it uses Emotion and Lens components).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to encourage extension developers to use SCSS, then you need:
- to provide these SCSS files via some NPM package import;
- document what all these variables are and where they should be used;
- make sure that all your extension examples come with SCSS processor "built-in" to the build (none of them do, right now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there's no urge for now to encourage developers to use exactly SCSS since the only benefit currently is to use few basic variables. I've transfered them into CSS vars and removed encouragement message.
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>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
@stefcameron Thanks for your detailed feedback! I've made changes and added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we make theming files as pure css-files instead of json
?
Like this:
/**
@file theme/lens-some-theme.css
@name Lens Dark
@type dark
@description Original Lens dark theme
@author Mirantis
*/
:root {
--mainBackground: green;
// ...
}
Pros:
- easier to navigate in project + refactor when needed
- easier to apply theme (turn on/off
style
element) - all colors preview are shown in editor when file is opened (e.g. vscode, webstorm)
- comments inside
.css
are allowed
Cons:
- to show theme's metadata we would need to parse jsdoc (or similar) top comment
$font-main: var(--font-main); | ||
$font-monospace: var(--font-monospace); | ||
$font-size-small: var(--font-size-small); | ||
$font-size: var(--font-size); | ||
$font-size-big: var(--font-size-big); | ||
$font-weight-thin: var(--font-weight-thin); | ||
$font-weight-normal: var(--font-weight-normal); | ||
$font-weight-bold: var(--font-weight-bold); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need all these scss-var -> css-var
aliases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, since the values were moved into CSS Vars -- unless you SCSS code references the CSS Vars directly, but if that were the case, then I would imagine there would be many more files updated in this PR to move away from using the SCSS variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvements! Having that color reference, as well as the layout and font variable references, will be a huge help to developers!
|
||
## Styling approach | ||
Lens heavily uses SCSS preprocessor and it's advised to stick with same approach for extension developers in order to use some of the predefined variables and mixins described below. | ||
Lens heavily uses SCSS preprocessor with a set of predefined variables and mixins. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you've now moved everything pertinent to extensions into CSS variables, I would recommend removing this line. Extensions don't need to care about how Lens does things internally. They should only care about how they're supposed to do things, and what Lens does that will affect them (namely, the CSS variables available to them, as well as anything that would affect layout like flex.box
, which you mention below).
$font-main: var(--font-main); | ||
$font-monospace: var(--font-monospace); | ||
$font-size-small: var(--font-size-small); | ||
$font-size: var(--font-size); | ||
$font-size-big: var(--font-size-big); | ||
$font-weight-thin: var(--font-weight-thin); | ||
$font-weight-normal: var(--font-weight-normal); | ||
$font-weight-bold: var(--font-weight-bold); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, since the values were moved into CSS Vars -- unless you SCSS code references the CSS Vars directly, but if that were the case, then I would imagine there would be many more files updated in this PR to move away from using the SCSS variable names.
This is something to consider. It would add one less step of indirection between styles and their definition. But note that there are JSON parsers out there that support comments, so you could still add comments in your JSON file, albeit that may be difficult depending on what is parsing that JSON file (if you can customize the parser it uses). JSON or CSS, however, I think the best thing here would be to colocate the definition of the variables with the variables themselves. IMO, the closer the docs are to the code, the more likely they are to remain accurate. So if we could take all those color variable explanations in On a related note, since Lens is using CSS variables, this article might be interesting, particularly how Kent implements theme switching with |
Note to reviewers: let's improve things in follow-up PRs 🙂 |
Building on lensapp#1267 and iterating on the docs, re-organizing them into Layout and Theme sections. Also adding sample code on how to detect theme changes in JavaScript.
Building on lensapp#1267 and iterating on the docs, re-organizing them into Layout and Theme sections. Also adding sample code on how to detect theme changes in JavaScript. Signed-off-by: Stefan Cameron <stefancameron@SC-MBPt13-2018.austin.rr.com>
Building on #1267 and iterating on the docs, re-organizing them into Layout and Theme sections. Also adding sample code on how to detect theme changes in JavaScript. Signed-off-by: Stefan Cameron <stefancameron@SC-MBPt13-2018.austin.rr.com>
Signed-off-by: Alex Andreev alex.andreev.email@gmail.com