mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Adding more details to styling section
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
8e3223d30c
commit
26b225486a
BIN
docs/extensions/capabilities/images/css-vars-in-devtools.png
Normal file
BIN
docs/extensions/capabilities/images/css-vars-in-devtools.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
docs/extensions/capabilities/images/theme-selector.png
Normal file
BIN
docs/extensions/capabilities/images/theme-selector.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 408 KiB |
@ -1,8 +1,8 @@
|
||||
# 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.
|
||||
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.
|
||||
|
||||
## 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.
|
||||
|
||||
For layout tasks Lens is using [flex.box](https://www.npmjs.com/package/flex.box) library which provides helpful class names to specify some of the [flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox) properties. For example, `div` with class names:
|
||||
```
|
||||
@ -21,12 +21,10 @@ However, feel free to use any styling technique or framework like [Emotion](http
|
||||
|
||||
## Themes
|
||||
Lens using 2 built-in themes located in `src/renderer/themes` folder each for light and dark color schemes. Active theme can be changed in the `Preferences` page.
|
||||
|
||||
[theme selector]
|
||||

|
||||
|
||||
When Lens gets loaded it transforms selected theme `json` file into list of [CSS Custom Properties (CSS Variables)](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) which then gets injected into `:root` element so any of the down-level components can use them.
|
||||
|
||||
[css vars listed in devtools]
|
||||

|
||||
|
||||
When user changes a theme, the process is repeated, new css variables appear instead of previous ones.
|
||||
|
||||
@ -38,67 +36,64 @@ Every extention is affected by list of default global styles defined in `src/ren
|
||||
Extension may overwrite them if needed.
|
||||
|
||||
## Variables to use
|
||||
|
||||
### vars.scss
|
||||
In `src/renderer/components/vars.scss` there are list of predefined variables mostly for dimensions and fonts.
|
||||
### Basic styling
|
||||
There is a list of CSS Variables available for extension to use. Basic variables located inside `:root` selected in `src/renderer/components/app.scss`:
|
||||
```
|
||||
// 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;
|
||||
...
|
||||
--unit: 8px;
|
||||
--padding: var(--unit);
|
||||
--margin: var(--unit);
|
||||
--border-radius: 3px;
|
||||
--font-main: 'Roboto', 'Helvetica', 'Arial', sans-serif;
|
||||
--font-monospace: Lucida Console, Monaco, Consolas, monospace;
|
||||
--font-size-small: calc(1.5 * var(--unit));
|
||||
--font-size: calc(1.75 * var(--unit));
|
||||
--font-size-big: calc(2 * var(--unit));
|
||||
--font-weight-thin: 300;
|
||||
--font-weight-normal: 400;
|
||||
--font-weight-bold: 500;
|
||||
```
|
||||
|
||||
You can use them to set consistent paddings, define font-sizes in your SCSS files e.g.
|
||||
They're intended to set consistent paddings and font-sizes across components, e.g.
|
||||
```
|
||||
.status {
|
||||
padding-left: $padding * 2;
|
||||
font-size: $font-size-small;
|
||||
padding-left: calc(var(--padding) * 2);
|
||||
font-size: var(--font-size-small);
|
||||
}
|
||||
```
|
||||
|
||||
### 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.
|
||||
### Themable colors
|
||||
After theme file gets parsed it provides 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.
|
||||
```
|
||||
// Base colors
|
||||
$lensBlue: var(--blue);
|
||||
$lensMagenta: var(--magenta);
|
||||
$golden: var(--golden);
|
||||
$halfGray: var(--halfGray);
|
||||
$primary: var(--primary);
|
||||
$textColorPrimary: var(--textColorPrimary);
|
||||
$textColorSecondary: var(--textColorSecondary);
|
||||
$textColorAccent: var(--textColorAccent);
|
||||
$borderColor: var(--borderColor);
|
||||
$borderFaintColor: var(--borderFaintColor);
|
||||
$colorSuccess: var(--colorSuccess);
|
||||
$colorOk: var(--colorOk);
|
||||
$colorInfo: var(--colorInfo);
|
||||
$colorError: var(--colorError);
|
||||
$colorSoftError: var(--colorSoftError);
|
||||
$colorWarning: var(--colorWarning);
|
||||
$colorVague: var(--colorVague);
|
||||
$colorTerminated: var(--colorTerminated);
|
||||
|
||||
// Layout
|
||||
$mainBackground: var(--mainBackground);
|
||||
$contentColor: var(--contentColor);
|
||||
$layoutBackground: var(--layoutBackground);
|
||||
$layoutTabsBackground: var(--layoutTabsBackground);
|
||||
"blue": "#3d90ce",
|
||||
"magenta": "#c93dce",
|
||||
"golden": "#ffc63d",
|
||||
"halfGray": "#87909c80",
|
||||
"primary": "#3d90ce",
|
||||
"textColorPrimary": "#555555",
|
||||
"textColorSecondary": "#51575d",
|
||||
"textColorAccent": "#333333",
|
||||
"borderColor": "#c9cfd3",
|
||||
"borderFaintColor": "#dfdfdf",
|
||||
"mainBackground": "#f1f1f1",
|
||||
"contentColor": "#ffffff",
|
||||
"layoutBackground": "#e8e8e8",
|
||||
"layoutTabsBackground": "#f8f8f8",
|
||||
"layoutTabsActiveColor": "#333333",
|
||||
"layoutTabsLineColor": "#87909c80"
|
||||
...
|
||||
...
|
||||
```
|
||||
**Note**: if you don't use SCSS preprocessor in your extenstion **you can inlcude CSS Variables directly `var(--mainBackground)`**;
|
||||
|
||||
### mixins.scss
|
||||
In `src/renderer/components/mixins.scss` there are some useful utylity styles such as theme-aware scrollbar.
|
||||
They can be used in form of `var(--magenta)`.
|
||||
|
||||
A complete list of all themable colors can be found in the [color reference](color-reference).
|
||||
|
||||
Colors values are located inside `src/renderer/themes/lens-dark.json` and `src/renderer/themes/lens-light.json` files.
|
||||
|
||||
## Using CSS Variables inside CSS-in-JS components
|
||||
If a developer uses an `Emotion` (or similar) framework to work with styles inside an extension, they can use variables in the following form:
|
||||
```
|
||||
const Container = styled.div(() => ({
|
||||
backgroundColor: 'var(--mainBackground)'
|
||||
}));
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user