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

Sass configuration refactor #154

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
859e570
somehow this actually works
whiplashwebb Jan 8, 2025
459f337
primary bulma seems to work?
whiplashwebb Jan 10, 2025
2187e97
notes
whiplashwebb Jan 13, 2025
112b525
added more test vars, naturally everything breaks again
whiplashwebb Jan 13, 2025
a67def3
working again. i guess the issue was missing defaults?!!
whiplashwebb Jan 13, 2025
0234418
customer color test
whiplashwebb Jan 13, 2025
55f8222
create some separation between build and dev entrypoints to remove du…
whiplashwebb Jan 13, 2025
57a0899
cleanup
whiplashwebb Jan 13, 2025
914a9ce
split out use cases
whiplashwebb Jan 14, 2025
5dcaa51
separated actually works!
whiplashwebb Jan 14, 2025
8adb984
refactoring, docs
whiplashwebb Jan 14, 2025
11e3b6f
readme
whiplashwebb Jan 14, 2025
aafe2fa
add pack command are related ignore
whiplashwebb Jan 15, 2025
a44fcc4
add derrived to deal with param hoisting problem, fix checkbox
whiplashwebb Jan 15, 2025
5961301
carousel
whiplashwebb Jan 15, 2025
fb175e3
datepicker and dropdown
whiplashwebb Jan 15, 2025
2b14863
field
whiplashwebb Jan 15, 2025
d19b152
incons
whiplashwebb Jan 15, 2025
e9577a6
loading
whiplashwebb Jan 15, 2025
c6df699
notifications
whiplashwebb Jan 15, 2025
7fccf65
radio
whiplashwebb Jan 15, 2025
3a98fa9
sidebar
whiplashwebb Jan 15, 2025
96192f3
skeleton
whiplashwebb Jan 15, 2025
94f6879
slider
whiplashwebb Jan 15, 2025
95190f0
steps
whiplashwebb Jan 15, 2025
2995137
switch
whiplashwebb Jan 15, 2025
2458a07
table
whiplashwebb Jan 15, 2025
96c8ac4
tabs
whiplashwebb Jan 15, 2025
aee3e46
taginput
whiplashwebb Jan 15, 2025
f564dc5
tooltip
whiplashwebb Jan 15, 2025
f0230ca
upload
whiplashwebb Jan 15, 2025
83d7835
renaming
whiplashwebb Jan 15, 2025
4ee57dc
cleanup todo, add doc annotations
whiplashwebb Jan 20, 2025
c8b341b
a little more commentary
whiplashwebb Jan 20, 2025
fde3ea1
fix typo
whiplashwebb Jan 20, 2025
022363d
remove unused @use
whiplashwebb Jan 27, 2025
bccdaaf
remove extra forward
whiplashwebb Jan 27, 2025
4925060
refactor to separate component defaults
whiplashwebb Jan 31, 2025
f8aa5ff
missing forward
whiplashwebb Jan 31, 2025
fe1be7d
update annotations, redistribute inititial defaults
whiplashwebb Jan 31, 2025
21077c0
missing barrel entries
whiplashwebb Jan 31, 2025
fef3d5f
removed stray use
whiplashwebb Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist-ssr
*.log
.vscode
.idea
*.tgz
90 changes: 57 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,65 +48,89 @@ Please note, this package can be used without importing any other Oruga styling

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/)).

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.
To overwrite Bulma’s Sass variables with your own values, you have to use `@use` and the `with` keyword, which takes a Sass map.
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.
To use the examples below start by creating a custom sass/scss file like `main.scss` (you can call it anything) and import it instead of `bulma.css` like this:

```scss
// Option A: Include all styling (including bulma)
```js
import { createApp } from 'vue'
import App from './App.vue'

import Oruga from '@oruga-ui/oruga-next'
import { bulmaConfig } from '@oruga-ui/theme-bulma'

import './main.scss'

createApp(App)
.use(Oruga, bulmaConfig)
.mount('#app')
```

Inside `main.scss` you need to include Bulma styles and theme styles. You have two options for doing it: **combined** or **separated**. The theme features a combined entrypoint which includes Bulma styles and theme styles. This is best for most customization use cases as it handles some messy variable scope issues. The separated entrypoint only includes theme styles without Bulma. This gives you full control over how you import Bulma and how much of it you import, but you'll have to deal with the messy scope problems mentioned earlier. Unless it's critical you only include part of Bulma the separate method is best avoided.

#### The Combined Method

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.

If you need to add custom color variants with this method you must use the `$theme-bulma-custom-colors` variable.

```scss
// set your color overrides
$primary: #8c67ef;
$red: #f00;
$link: $primary;

// add new colors to the colors map
$twitter: #4099FF;
$custom-colors: ('twitter': $twitter);
$theme-bulma-custom-colors: ('tertiary': $red);

// Include the Oruga Bulma theme with Bulma included (you can only manipulate any derived variables here)
// Include the Oruga Bulma theme with Bulma included
@use '@oruga-ui/theme-bulma/dist/scss/bulma-build' with (
$family-primary: '"Nunito", sans-serif',
$primary: $primary,
$link: $link,
$custom-colors: $custom-colors,
$theme-bulma-custom-colors: $custom-colors,
);

// Then add additional custom code here
// ...
```
**_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.

```scss
// Option B: Include the Oruga theme and Bulma separately
#### The Separated Method
When using this method the main thing to be aware of is `$custom-colors`. 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 need to do this in your code instead using Bulma's `$custom-colors` var, which will be implicitly passed to the theme behind the scenes.

// set your color overrides
$primary: #8c67ef;
$link: $primary;

// add new colors to the colors map
$twitter: #4099FF;
$custom-colors: ('twitter': $twitter);
```scss
// Assemble color variables
$red: #f00;
$green: #0f0;
$blue: #00f;
$black: #000;
$dark-grey: #6c757d;
$speed-slower: 1000ms;

// Custom colors is required if you want the secondary variant. Nothing will break if you omit it though.
$custom-colors: (
// Add the standard Oruga secondary variant
'secondary': $dark-grey,
// If you want to add additional custom colors add them here
'tertiary': $red
);

// 1. Include the Oruga theme first (you can only manipulate any derived variables here)
@use '@oruga-ui/theme-bulma/dist/scss/bulma' with (
$family-primary: '"Nunito", sans-serif',
$primary: $primary,
$link: $link,
// Pass any Bulma vars you'd like to override here
@use "bulma/sass" with (
$red: $red,
$blue: $blue,
$green: $green,
$black: $black,
$primary: $green,
$custom-colors: $custom-colors,
);

// 2. Include any other Bulma module with specific configuration here
@use "bulma/sass/elements" with (
$button-weight: 800
// Pass any theme vars you'd like to override here
@use "@oruga-ui/theme-bulma/dist/scss/component-only-build.scss" with (
$speed-slower: $speed-slower,
);

// 3. Include the remaining parts or full Bulma
@use "bulma/sass";

// Then add additional custom code here
// ...
```

The other thing to be aware of is when you're importing Bulma. `@use "bulma/sass" with (...)` **MUST** come before all other Bulma usage. This is where the messy scope issues come in. If you reference Bulma beforehand, for example to use a Bulma mixin to create a color to pass into Bulma, you're going to get SASS errors.

### Override default config

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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"build": "vue-tsc --noEmit && vite build",
"lint": "eslint . --fix --quiet",
"lint:style": "stylelint **/*.{css,scss} --fix --ignore-path .gitignore",
"update": "ncu -u"
"update": "ncu -u",
"pack:lib": "rm -rf dist && npm run build && echo \"$PWD/$(npm pack)\""
whiplashwebb marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"@oruga-ui/oruga-next": "^0.9.0"
Expand Down
11 changes: 11 additions & 0 deletions src/assets/scss/_derived-defaults.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is home to defaulted variables which DO reference bulma but are not part of a particular component

@use "bulma/sass/utilities/derived-variables" as dv;

$sizes-map: (
"small": dv.$size-small,
"normal": dv.$size-normal,
"medium": dv.$size-medium,
"large": dv.$size-large,
) !default;

23 changes: 23 additions & 0 deletions src/assets/scss/_initial-defaults.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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

@use "sass:map";

$speed-slow: 150ms !default;
$speed-slower: 250ms !default;

// oruga defines an extra secondary color
$secondary: #6c757d !default;

// alternative to focus-shadow-size
$active-shadow-size: 0 0 0.5em !default;

// renamed with theme-bulma prefix to avoid namespace collision with the @forward below
$theme-bulma-custom-colors: () !default;

// Merge any user-defined custom colors with the custom colors defined by the theme. This will be passes to Bulma as $custom-colors
// 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
$theme-bulma-custom-colors-merged: map.merge(
// merge our custom-colors with the overridable map
("secondary": $secondary),
$theme-bulma-custom-colors
);
18 changes: 16 additions & 2 deletions src/assets/scss/bulma-build.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
@forward "components/utils/all";
@forward "bulma/sass";
// This file is the entrypoint for the main css build (bulma.css)
// It is also the scss entrypoint for users who want to configure Bulma and the theme together

// Theme defaults must be explictly forwarded here, otherwise confusing error messages result from the lack of defaults.
@forward "initial-defaults";
@use "initial-defaults" as td;

// the primary bulma forward must come before all usage to prevent issues where usage appears before the with() statement
@forward "bulma/sass" with (
$custom-colors: td.$theme-bulma-custom-colors-merged,
);

@forward "derived-defaults";
@forward "component-defaults";

// Theme component scss
@forward "bulma";
Copy link
Member

Choose a reason for hiding this comment

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

Looks good so far. Could you explain to me again why we have to have the component variables in their own files in the "component-defaults" folder and can't have them in the "components" folder files?
I'm a bit confused because the @forward "component-defaults"; comes just before the @forward "bulma"; not only in this file, but also in the "component-only-build.scss" file...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's the hoisting problem. if you put the defaults in the main component files then if the default is used the whole file gets hoisted. this isn't a problem for the defaults generally, but it will hoist other use or forward statements in the file, which typically shifts a Bulma @use before the primary Bulma @use with (...). There are a few files which don't use Bulma like that where in theory we could get away with putting them together, but that's the exception rather than the rule, and i think the mixing of patterns will just confuse future coders. trust me, this pattern feel inelegant to me too, but it seems to be unavoidable.

14 changes: 14 additions & 0 deletions src/assets/scss/component-defaults/_carousel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$carousel-arrow-icon-spaced: 1.5rem !default;
$carousel-arrow-top: 50% !default;
$carousel-indicator-spaced: 0.5rem !default;
$carousel-overlay-z: 40 !default;
$carousel-arrow-background: css.getVar("scheme-main") !default;
$carousel-arrow-color: css.getVar("primary") !default;
$carousel-indicator-background: rgba(css.getVar("scheme-invert"), 0.5) !default;
$carousel-indicator-border: css.getVar("scheme-main") !default;
$carousel-indicator-color: css.getVar("primary") !default;
$carousel-overlay-background: rgba(css.getVar("scheme-invert"), 0.86) !default;
/* @docs */
18 changes: 18 additions & 0 deletions src/assets/scss/component-defaults/_checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$checkbox-size: 1.25em !default;
$checkbox-background-color: transparent !default;
$checkbox-border-width: 2px !default;
$checkbox-colors: dv.$colors !default;
$checkbox-border-color: css.getVar("grey") !default;
$checkbox-border-radius: css.getVar("radius") !default;
$checkbox-checkmark-color: css.getVar("primary-invert") !default;
$checkbox-focus-color: hsl(from css.getVar("grey") h s l / 80%) !default;
$checkbox-active-focus-color: hsl(
from css.getVar("checkbox-active-background-color") h s l / 80%
) !default;
$checkbox-active-background-color: css.getVar("primary") !default;
$checkbox-shadow: css.getVar("shadow");
/* @docs */
15 changes: 15 additions & 0 deletions src/assets/scss/component-defaults/_datepicker.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$datepicker-colors: dv.$colors !default;
$datepicker-header-color: css.getVar("grey") !default;
$datepicker-today-border: solid 1px rgba(css.getVar("primary"), 0.5) !default;
$datepicker-item-color: css.getVar("grey-dark") !default;
$datepicker-item-disabled-color: css.getVar("grey-light") !default;
$datepicker-item-hover-color: css.getVar("scheme-invert") !default;
$datepicker-item-hover-background-color: css.getVar("background") !default;
$datepicker-item-selected-color: css.getVar("primary-invert") !default;
$datepicker-item-selected-background-color: css.getVar("primary") !default;
$datepicker-event-background-color: css.getVar("grey-light") !default;
/* @docs */
16 changes: 16 additions & 0 deletions src/assets/scss/component-defaults/_dropdown.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@use "bulma/sass/utilities/initial-variables" as iv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$dropdown-content-max-height: 200px !default;
$dropdown-disabled-opacity: 0.5 !default;
$dropdown-gap: 0px !default;
$dropdown-z: 40 !default;
$dropdown-mobile-breakpoint: iv.$desktop !default;
$dropdown-background-background-color: hsla(
#{css.getVar("scheme-h")},
#{css.getVar("scheme-s")},
#{css.getVar("scheme-invert-l")},
0.86
) !default;
/* @docs */
3 changes: 3 additions & 0 deletions src/assets/scss/component-defaults/_field.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @docs */
$floating-in-height: 3.25em !default;
/* @docs */
3 changes: 3 additions & 0 deletions src/assets/scss/component-defaults/_icon.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @docs */
$icon-spin-duration: 2s !default;
/* @docs */
19 changes: 19 additions & 0 deletions src/assets/scss/component-defaults/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@forward "carousel";
@forward "checkbox";
@forward "datepicker";
@forward "dropdown";
@forward "field";
@forward "icon";
@forward "loading";
@forward "notification";
@forward "radio";
@forward "sidebar";
@forward "skeleton";
@forward "slider";
@forward "steps";
@forward "switch";
@forward "table";
@forward "tabs";
@forward "taginput";
@forward "tooltip";
@forward "upload";
6 changes: 6 additions & 0 deletions src/assets/scss/component-defaults/_loading.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* @docs */
$loading-background-color: rgba(255, 255, 255, 0.5) !default;
$loading-icon-size: 3em !default;
$loading-icon-size-full-page: 5em !default;
$loading-z: 29 !default;
/* @docs */
5 changes: 5 additions & 0 deletions src/assets/scss/component-defaults/_notification.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* @docs */
$notification-margin-bottom: 1.5rem !default;
$notification-notices-padding: 2em !default;
$notification-notices-z: 1000 !default;
/* @docs */
10 changes: 10 additions & 0 deletions src/assets/scss/component-defaults/_radio.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$radio-size: 1.25em !default;
$radio-colors: dv.$colors !default;
$radio-active-background-color: css.getVar("primary") !default;
$radio-border-color: css.getVar("grey") !default;
$radio-shadow: css.getVar("shadow");
/* @docs */
17 changes: 17 additions & 0 deletions src/assets/scss/component-defaults/_sidebar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$sidebar-z: 40;
$sidebar-width: 260px !default;
$sidebar-height: 260px !default;
$sidebar-mobile-width: 80px !default;
$sidebar-colors: dv.$colors !default;
$sidebar-background-background-color: hsla(
#{css.getVar("scheme-h")},
#{css.getVar("scheme-s")},
#{css.getVar("scheme-invert-l")},
0.86
) !default;
$sidebar-shadow: css.getVar("shadow");
/* @docs */
7 changes: 7 additions & 0 deletions src/assets/scss/component-defaults/_skeleton.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$skeleton-duration: 1.5s !default;
$skeleton-margin-top: 0.5rem !default;
$skeleton-border-radius: css.getVar("radius") !default;
/* @docs */
21 changes: 21 additions & 0 deletions src/assets/scss/component-defaults/_slider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$slider-tick-label-size: 0.75rem !default;
$slider-thumb-shadow: none !default;
$slider-thumb-to-track-ratio: 2 !default;
$slider-tick-to-track-ratio: 0.5 !default;
$slider-tick-width: 3px !default;
$slider-colors: dv.$colors !default;
$slider-radius: css.getVar("radius") !default;
$slider-background: css.getVar("grey-lighter") !default;
$slider-color: css.getVar("primary") !default;
$slider-track-border: 0px solid css.getVar("grey") !default;
$slider-track-shadow: 0px 0px 0px css.getVar("grey") !default;
$slider-thumb-background: css.getVar("scheme-main") !default;
$slider-thumb-radius: css.getVar("radius") !default;
$slider-thumb-border: 1px solid css.getVar("grey-light") !default;
$slider-tick-radius: css.getVar("radius") !default;
$slider-tick-background: css.getVar("grey-light") !default;
/* @docs */
19 changes: 19 additions & 0 deletions src/assets/scss/component-defaults/_steps.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@use "bulma/sass/utilities/initial-variables" as iv;
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$steps-divider-height: 0.2em !default;
$steps-vertical-padding: 1em 0 !default;
$steps-colors: dv.$colors !default;
$steps-mobile-breakpoint: iv.$tablet !default;
$steps-marker-background: css.getVar("grey-light") !default;
$steps-marker-color: css.getVar("scheme-main") !default;
$steps-marker-border: 0.2em solid css.getVar("white") !default;
$steps-default-color: css.getVar("grey-lighter") !default;
$steps-previous-color: css.getVar("scheme-main") !default;
$steps-previous-background: css.getVar("primary") !default;
$steps-active-color: css.getVar("primary") !default;
$steps-active-background: css.getVar("scheme-main") !default;
$steps-details-background-color: css.getVar("body-background-color") !default;
/* @docs */
11 changes: 11 additions & 0 deletions src/assets/scss/component-defaults/_switch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/css-variables" as css;

/* @docs */
$switch-width: 2.75em !default;
$switch-padding: 0.2em !default;
$switch-colors: dv.$colors !default;
$switch-background-color: css.getVar("grey-light") !default;
$switch-active-background-color: css.getVar("primary") !default;
$switch-shadow: css.getVar("shadow");
/* @docs */
3 changes: 3 additions & 0 deletions src/assets/scss/component-defaults/_table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @docs */
$table-sticky-header-height: 300px !default;
/* @docs */
Loading