Skip to content

Commit 27b9298

Browse files
feat: restructure sass configuration (#154)
Co-authored-by: mlmoravek <marcel.moravek@yahoo.de>
1 parent 63921c2 commit 27b9298

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+679
-496
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist-ssr
66
*.log
77
.vscode
88
.idea
9+
*.tgz

README.md

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,65 +48,101 @@ Please note, this package can be used without importing any other Oruga styling
4848

4949
Bulma is a highly customizable CSS framework. From colors to typography, spacing and sizes, forms and layouts, all parts of Bulma can be customized by the user (see [Bulma Customization](https://bulma.io/documentation/customize/concepts/)).
5050

51-
Using the following sample code you **don't need** `import '@oruga-ui/theme-bulma/dist/bulma.css'` but you have to add a custom sass/scss file to customize Bulma and the theme variables.
52-
To overwrite Bulma’s Sass variables with your own values, you have to use `@use` and the `with` keyword, which takes a Sass map.
53-
You have two options for including the theme: include all the styling at once (including full bulma), or include the Oruga theme and Bulma separately.
51+
Using the following sample code below you **don't need** `import '@oruga-ui/theme-bulma/dist/bulma.css'` but you have to add a custom sass/scss file (like `main.scss`) to customize Bulma and the theme variables.
52+
53+
```js
54+
import { createApp } from 'vue'
55+
import App from './App.vue'
56+
57+
import Oruga from '@oruga-ui/oruga-next'
58+
import { bulmaConfig } from '@oruga-ui/theme-bulma'
59+
60+
import './main.scss'
61+
62+
createApp(App)
63+
.use(Oruga, bulmaConfig)
64+
.mount('#app')
65+
```
66+
67+
Inside your own sass/scss file you need to include Bulma styles and theme styles. To overwrite sass variables with your own values, you have to use `@use` and the `with` keyword, which takes a Sass map.
68+
69+
There are two ways of importing the theme style:
70+
- **combined** - The theme features a combined entrypoint which includes Bulma styles and theme styles. This is best for most customization use cases.
71+
- **separated**- The separated entrypoint only contains theme styles without Bulma. This gives you full control over how and how much of Bulma you import, but you'll have to deal with the sass variable scoping yourself. Unless it's critical that you only include part of Bulma, the separate method is best avoided.
72+
73+
#### The Combined Method
74+
75+
The combined method is fairly straitforward. Define custom variables and then pass them in using `with()` syntax. You can override any variable in Bulma or the theme which has a `!default` by passing it in this way.
76+
77+
If you need to add custom color variants with this method you must use the `$theme-bulma-custom-colors` variable.
5478

5579
```scss
5680
// Option A: Include all styling (including bulma)
5781

58-
// set your color overrides
82+
// Set your color overrides
5983
$primary: #8c67ef;
84+
$red: #f00;
6085
$link: $primary;
6186

62-
// add new colors to the colors map
63-
$twitter: #4099FF;
64-
$custom-colors: ('twitter': $twitter);
87+
// Add new colors to the colors map
88+
$theme-bulma-custom-colors: ('tertiary': $red);
6589

66-
// Include the Oruga Bulma theme with Bulma included (you can only manipulate any derived variables here)
90+
// Include the Oruga Bulma theme with Bulma included
6791
@use '@oruga-ui/theme-bulma/dist/scss/bulma-build' with (
6892
$family-primary: '"Nunito", sans-serif',
6993
$primary: $primary,
7094
$link: $link,
71-
$custom-colors: $custom-colors,
95+
$theme-bulma-custom-colors: $custom-colors,
7296
);
7397

7498
// Then add additional custom code here
7599
// ...
76100
```
77-
**_NOTE:_** Note that only variables within Bulma's [derived-variables.scss](https://github.com/jgthms/bulma/blob/main/sass/utilities/derived-variables.scss) file can be overridden here.
101+
102+
#### The Separated Method
103+
When using this method, you will lose the theme customisation for the Bulma variables.
104+
In the combined method the theme will add Oruga's standard `secondary` color variant for you and you can add additional variants using `$theme-bulma-custom-colors`. Using the separate method, you have to do this in your code instead using Bulma's `$custom-colors` var, which will be implicitly passed to the theme behind the scenes.
105+
You have to be aware of importing Bulma, `@use "bulma/sass" with (...)` before any other Bulma usage. If you reference Bulma beforehand, for example to use a Bulma mixin to create a colour to pass to Bulma, you will get sass scope problems.
78106

79107
```scss
80108
// Option B: Include the Oruga theme and Bulma separately
81109

82-
// set your color overrides
83-
$primary: #8c67ef;
84-
$link: $primary;
85-
86-
// add new colors to the colors map
87-
$twitter: #4099FF;
88-
$custom-colors: ('twitter': $twitter);
110+
// Assemble color variables
111+
$red: #f00;
112+
$green: #0f0;
113+
$blue: #00f;
114+
$black: #000;
115+
$dark-grey: #6c757d;
116+
$speed-slower: 1000ms;
117+
118+
// Custom colors is required if you want the secondary variant. Nothing will break if you omit it though.
119+
$custom-colors: (
120+
// Add the standard Oruga secondary variant
121+
'secondary': $dark-grey,
122+
// If you want to add additional custom colors to the colors map add them here
123+
'tertiary': $red
124+
);
89125

90-
// 1. Include the Oruga theme first (you can only manipulate any derived variables here)
91-
@use '@oruga-ui/theme-bulma/dist/scss/bulma' with (
92-
$family-primary: '"Nunito", sans-serif',
93-
$primary: $primary,
94-
$link: $link,
126+
// Pass any Bulma variables you'd like to override here
127+
@use "bulma/sass" with (
128+
$red: $red,
129+
$blue: $blue,
130+
$green: $green,
131+
$black: $black,
132+
$primary: $green,
95133
$custom-colors: $custom-colors,
96134
);
97135

98-
// 2. Include any other Bulma module with specific configuration here
99-
@use "bulma/sass/elements" with (
100-
$button-weight: 800
136+
// Pass any theme variables you'd like to override here
137+
@use "@oruga-ui/theme-bulma/dist/scss/components-build.scss" with (
138+
$speed-slower: $speed-slower,
101139
);
102140

103-
// 3. Include the remaining parts or full Bulma
104-
@use "bulma/sass";
105-
106141
// Then add additional custom code here
107142
// ...
108143
```
109144

145+
110146
### Override default config
111147

112148
In case you want to replace the default style of a component you can override or add new classes changing ``bulmaConfig``; more details about components customization on https://oruga-ui.com/documentation/customisation.html
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is home to defaulted variables which DO reference bulma but are not part of a particular component
2+
3+
@use "bulma/sass/utilities/derived-variables" as dv;
4+
5+
$sizes-map: (
6+
"small": dv.$size-small,
7+
"normal": dv.$size-normal,
8+
"medium": dv.$size-medium,
9+
"large": dv.$size-large,
10+
) !default;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is home to defaulted variables which need to be passed to Bulma, or to general defaulted variables which are not part of a particular component
2+
3+
@use "sass:map";
4+
5+
$speed-slow: 150ms !default;
6+
$speed-slower: 250ms !default;
7+
8+
// oruga defines an extra secondary color
9+
$secondary: #6c757d !default;
10+
11+
// alternative to focus-shadow-size
12+
$active-shadow-size: 0 0 0.5em !default;
13+
14+
// renamed with theme-bulma prefix to avoid namespace collision with the @forward below
15+
$theme-bulma-custom-colors: () !default;
16+
17+
// Merge any user-defined custom colors with the custom colors defined by the theme. This will be passes to Bulma as $custom-colors
18+
// This is the one variable in this file which is not defaulted, but it collects defaulted values so it counts. It's going to be passed into bulma so it has to be here so it comes first
19+
$theme-bulma-custom-colors-merged: map.merge(
20+
// merge our custom-colors with the overridable map
21+
(
22+
"secondary": $secondary,
23+
),
24+
$theme-bulma-custom-colors
25+
);

src/assets/scss/bulma-build.scss

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
@forward "components/utils/all";
2-
@forward "bulma/sass";
3-
@forward "bulma";
1+
// This file is the entrypoint for the main css build (bulma.css)
2+
// It is also the scss entrypoint for users who want to configure Bulma and the theme together
3+
4+
// theme defaults must be explictly forwarded here, otherwise confusing error messages result from the lack of defaults.
5+
@forward "initial-defaults";
6+
@use "initial-defaults" as td;
7+
8+
// the primary bulma forward must come before all usage to prevent issues where usage appears before the with() statement
9+
@forward "bulma/sass" with (
10+
$custom-colors: td.$theme-bulma-custom-colors-merged
11+
);
12+
13+
// use the oruga bulma theme
14+
@forward "components-build";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@use "bulma/sass/utilities/css-variables" as css;
2+
3+
/* @docs */
4+
$carousel-arrow-icon-spaced: 1.5rem !default;
5+
$carousel-arrow-top: 50% !default;
6+
$carousel-indicator-spaced: 0.5rem !default;
7+
$carousel-overlay-z: 40 !default;
8+
$carousel-arrow-background: css.getVar("scheme-main") !default;
9+
$carousel-arrow-color: css.getVar("primary") !default;
10+
$carousel-indicator-background: rgba(css.getVar("scheme-invert"), 0.5) !default;
11+
$carousel-indicator-border: css.getVar("scheme-main") !default;
12+
$carousel-indicator-color: css.getVar("primary") !default;
13+
$carousel-overlay-background: rgba(css.getVar("scheme-invert"), 0.86) !default;
14+
/* @docs */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@use "bulma/sass/utilities/derived-variables" as dv;
2+
@use "bulma/sass/utilities/css-variables" as css;
3+
4+
/* @docs */
5+
$checkbox-size: 1.25em !default;
6+
$checkbox-background-color: transparent !default;
7+
$checkbox-border-width: 2px !default;
8+
$checkbox-colors: dv.$colors !default;
9+
$checkbox-border-color: css.getVar("grey") !default;
10+
$checkbox-border-radius: css.getVar("radius") !default;
11+
$checkbox-checkmark-color: css.getVar("primary-invert") !default;
12+
$checkbox-focus-color: hsl(from css.getVar("grey") h s l / 80%) !default;
13+
$checkbox-active-focus-color: hsl(
14+
from css.getVar("checkbox-active-background-color") h s l / 80%
15+
) !default;
16+
$checkbox-active-background-color: css.getVar("primary") !default;
17+
$checkbox-shadow: css.getVar("shadow");
18+
/* @docs */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@use "bulma/sass/utilities/derived-variables" as dv;
2+
@use "bulma/sass/utilities/css-variables" as css;
3+
4+
/* @docs */
5+
$datepicker-colors: dv.$colors !default;
6+
$datepicker-header-color: css.getVar("grey") !default;
7+
$datepicker-today-border: solid 1px rgba(css.getVar("primary"), 0.5) !default;
8+
$datepicker-item-color: css.getVar("grey-dark") !default;
9+
$datepicker-item-disabled-color: css.getVar("grey-light") !default;
10+
$datepicker-item-hover-color: css.getVar("scheme-invert") !default;
11+
$datepicker-item-hover-background-color: css.getVar("background") !default;
12+
$datepicker-item-selected-color: css.getVar("primary-invert") !default;
13+
$datepicker-item-selected-background-color: css.getVar("primary") !default;
14+
$datepicker-event-background-color: css.getVar("grey-light") !default;
15+
/* @docs */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@use "bulma/sass/utilities/initial-variables" as iv;
2+
@use "bulma/sass/utilities/css-variables" as css;
3+
4+
/* @docs */
5+
$dropdown-content-max-height: 200px !default;
6+
$dropdown-disabled-opacity: 0.5 !default;
7+
$dropdown-gap: 0px !default;
8+
$dropdown-z: 40 !default;
9+
$dropdown-mobile-breakpoint: iv.$desktop !default;
10+
$dropdown-background-background-color: hsla(
11+
#{css.getVar("scheme-h")},
12+
#{css.getVar("scheme-s")},
13+
#{css.getVar("scheme-invert-l")},
14+
0.86
15+
) !default;
16+
/* @docs */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* @docs */
2+
$floating-in-height: 3.25em !default;
3+
/* @docs */

0 commit comments

Comments
 (0)