wtho / bulma-css-vars Goto Github PK
View Code? Open in Web Editor NEWBulma with CSS Variables
Home Page: https://wtho.github.io/bulma-css-vars
License: MIT License
Bulma with CSS Variables
Home Page: https://wtho.github.io/bulma-css-vars
License: MIT License
I am working on a project where i need buefy 0.9.8
that is using Bulma 0.9.3
and bulma-css-vars for themes.
Thanks in advance.
Hi @wtho, thanks for the project!
I've got some trouble installing it on my project (I use Symfony Encore) but I finally got it working.
However, I had to change the example because it complained that ColorUpdater didn't have a constructor. (the variable was undefined)
I had to change the code a little bit to get it working:
import {ColorUpdater} from 'bulma-css-vars/dist/color-updater';
import bulmaCssVariablesDefs from './generated/bulma-colors';
const colorUpdater = new ColorUpdater(bulmaCssVariablesDefs);
colorUpdater.updateVarsInDocument(name, value);
Should I make a pull-request? I'm not sure that's the best way to do it.
(also, the JS example has minor typos, like : instead of ; so I'll probably make a request anyway ๐ )
Currently the fallback variables css file is generated by sass, but not minified. There could be an option to enable this.
Sadly, sass does not minify imported CSS, so we need to be able to minify it when creating it.
Hello there!
We love using Bulma at cssninjaStudio, but we think the release process does not fit the new modern way that we should follow.
Your package introduced a huge feature that we want to go through (switching to native css vars)
Nowadays, we got awesome features from native CSS engines (css vars, css4, hsl calc, ....) and only windycss or tailwind are going (to me) in the good way.
The idea would be to create and maintain a new fork of https://github.com/jgthms/bulma as a playground with new features.
We can then try those features and discuss them before getting into the official Bulma package.
We mainly want to go through these features:
The questions are:
I can get it working with Vue but under Nuxt I cannot get the sass loader to function. If anyone had a working example it would be very much appreciated.
Hi,
When i try to run "bulma-css-vars" locally (windows 10) i'm getting the following message:
(node:112956) UnhandledPromiseRejectionWarning: Error: [Bulma CSS Vars] cannot create definitions, entry sass file does not exist in file system at <blanked>\src\main.scss at <blanked>\node_modules\bulma-css-vars\dist\cli.js:58:19 at Generator.next (<anonymous>) at fulfilled (<blanked>\node_modules\bulma-css-vars\dist\cli.js:5:58) at <anonymous> at process._tickCallback (internal/process/next_tick.js:189:7) at Function.Module.runMain (module.js:696:11) at startup (bootstrap_node.js:204:16) at bootstrap_node.js:625:3 (node:112956) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:112956) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
However, the file absolutely exists in that location and consists of:
@import './bulma/generated-fallback.css'; // import fallbacks first, so they are overridden
@import './bulma/generated-vars.sass';
@import '../node_modules/bulma-css-vars/bulma-cv-lib';
bulma-css-vars.config.js has the following (excluding colour settings):
module.exports = {
sassEntryFile: './src/main.scss',
jsOutputFile: './src/bulma/bulma-colors.js',
sassOutputFile: './src/bulma/generated-vars.sass',
cssFallbackOutputFile: './src/bulma/generated-fallbacks.css',
colorDefs: appColors,
globalWebVar: false,
transition: '0.5s ease',
}
Following Buefy's recent update I was following the docs as I really could use smarter css variable colour handling for dynamic themes and started hitting this...
(node:10019) UnhandledPromiseRejectionWarning: Error: Can't find stylesheet to import.
โท
4 โ @import "../bulma/sass/utilities/derived-variables.sass"
โ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
โต
node_modules/bulma-css-vars/bulma-cv-utilities.sass 4:9 @import
node_modules/bulma-css-vars/bulma-cv-lib.sass 3:9 @import
src/main.scss 3:9 root stylesheet
Tracing it through, bulma-cv-utilities.sass
has @import "../bulma/sass/utilities/derived-variables.sass"
but it seems that files has become SCSS ../bulma/sass/utilities/derived-variables.scss
Buefy's new docs suggest Bulma 0.8 'or higher' - I guess I need to pin it to ~0.8.0?
When changing the colors via the ColorUpdater
in JS (like for a dark-theme toggle), the library should not just switch the color in a millisecond, but rather give the option to smoothly transition it.
This could be achieved by adding a new transition
option in bulma-css-vars.config.js
, e. g. like this:
transition: '2s ease'
and render this as transition: background-color 2s ease, color 2s ease;
for wherever css variables were added in.
PNPM throws constant deprecation warnings about source-map-resolve
which is due to the css
dependency.
Looking at this source-map-resolve
package it doesn't appear to have been updated in ~2 years, so potentially work looking into more current alternatives such as:
When I generate the files from my config not all colors are in the generated files.
Config file:
const { hsl } = require('bulma-css-vars');
const appColors = {
black: hsl(0, 0, 4),
'black-bis': hsl(0, 0, 7),
'black-ter': hsl(0, 0, 14),
'grey-darker': '#8a8f9c',
};
module.exports = {
jsOutputFile: 'src/bulma-generated/bulma-colors.js',
sassOutputFile: 'src/bulma-generated/generated-bulma-vars.sass',
cssFallbackOutputFile: 'src/bulma-generated/generated-fallback.css',
colorDefs: appColors,
sassEntryFile: 'src/main.scss',
transition: '0.3s ease',
};
Output:
module.exports = {
"bulmaCssVariablesDefs": {
"black": {
"calls": [
{
"fn": "rgba",
"fnArg": "10",
"composeArg": null
},
{
"fn": "rgba",
"fnArg": "2",
"composeArg": null
},
{
"fn": "rgba",
"fnArg": "20",
"composeArg": null
},
{
"fn": "rgba",
"fnArg": "5",
"composeArg": null
},
{
"fn": "lighten",
"fnArg": "800",
"composeArg": null
}
]
},
"grey-darker": {
"calls": [
{
"fn": "lighten",
"fnArg": "800",
"composeArg": null
},
{
"fn": "color-invert",
"fnArg": null,
"composeArg": null
}
]
}
}
}
So I add black
black-bis
black-ter
but only black
gets generated and grey-darker
works
hye, it seem to be a bigint problem caused by 0.039_28... but i do not understand ? any idea...
in ./node_modules/bulma-css-vars/node_modules/color/index.js friendly-errors 15:54:32
Module parse failed: Identifier directly after number (257:26) friendly-errors 15:54:32
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| for (const [i, element] of rgb.entries()) {
| const chan = element / 255;
> lum[i] = (chan <= 0.039_28) ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
| }
|
friendly-errors 15:54:32
@ ./node_modules/bulma-css-vars/dist/bulma-color-tools.js 4:14-30
@ ./node_modules/bulma-css-vars/dist/index.js
@ ./node_modules/esbuild-loader/dist??ref--11-0!./node_modules/vue-loader/lib??vue-loader-options!./components/layout/Navbar.vue?vue&type=script&lang=ts&
@ ./components/layout/Navbar.vue?vue&type=script&lang=ts&
@ ./components/layout/Navbar.vue
@ ./.nuxt/components/index.js
@ ./.nuxt/components/plugin.js
@ ./.nuxt/index.js
@ ./.nuxt/client.js
@ multi ./.nuxt/color-mode/script.js ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
thanks
One feature I'd like to see would be the possibility to change other properties, like the font-family.
The ColorUpdater wouldn't be needed, and you could simply do something like this:
document.documentElement.style.setProperty('--body-family', 'OpenSans, sans-serif');
However, I don't know if it fits the project. What's your opinion about this?
--
Sorry for the quick edit. I figured you can already do this with Bulma only. To use it with this project, I did the following in my main scss file:
@import './generated/generated-bulma-fallback.css';
@import './generated/generated-bulma-vars.sass';
:root {
--default-body-family: $body-family;
}
$body-family: var(--body-family, --default-body-family);
@import '../node_modules/bulma-css-vars/bulma-cv-lib.sass';
Hover and Focus state styles are missing.
const appColors = {
success: '#48c774'
}
.button.is-success:hover, .button.is-success.is-hovered {
background-color: var(--success);
border-color: transparent;
color: var(--success--color-invert);
}
.button.is-success:focus:not(:active), .button.is-success.is-focused:not(:active) {
box-shadow: 0 0 0 0.125em var(--success);
}
Hover colors should be a little darker. Focus colors should be rgba values.
.button.is-success {
background-color: #48c774;
border-color: transparent;
color: #fff;
}
.button.is-success:hover, .button.is-success.is-hovered {
background-color: #3ec46d;
border-color: transparent;
color: #fff;
}
.button.is-success:focus:not(:active), .button.is-success.is-focused:not(:active) {
box-shadow: 0 0 0 0.125em rgba(72, 199, 116, 0.25);
}
I was able to kind of fix this manually for a few elements but it would be way better if this could happen automagically.
// _my-project-variables.scss
@import '~/bulma/sass/utilities/functions.sass';
@import '~/bulma-css-vars/functions.sass';
$links: var(--links);
$input-focus-box-shadow-color: rgba($links, 0.25);
$button-focus-box-shadow-color: rgba($links, 0.25);
// theme-controller.js
// I am manually adding styles. This is probably not the cleanest way but it works...
let themeConfig = ':root {'
themeConfig += `--success--25--rgba: ${bulmaColorTools.rgba('#48c774', 25)};`
themeConfig += '}'
// style tag in index.html
document.getElementById('themeConfig').innerHTML = themeConfig;
/* patch-styles.css */
.button.is-success:focus:not(:active), .button.is-success.is-focused:not(:active) {
box-shadow: 0 0 0 .125em var(--success--25--rgba);
}
Thanks! This is an awesome package.
I'm using versions:
"buefy": "^0.8.4", "bulma": "^0.8.0", "bulma-css-vars": "^0.5.5",
When running the 'bulma-css-vars' script, I receive the following error - Please could you asssist? :
Executing task: npm run update-bulma-colors <
[email protected] update-bulma-colors C:\Code\StyleTest\test-styles
bulma-css-vars
(node:17312) UnhandledPromiseRejectionWarning: Error: Only 2 arguments allowed, but 4 were passed.
โโโ> node_modules\buefy\src\scss\components\_carousel.scss
133โ box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.25);
โ ^^^^^^^^^^^^^^^^^^^ invocation
โต
โโโ> node_modules\bulma-css-vars\functions.sass
51 โ @function rgba($col, $alpha)
โ โโโโโโโโโโโโโโโโโโ declaration
โต
node_modules\buefy\src\scss\components\_carousel.scss 133:34 rgba()
node_modules\buefy\src\scss\components\_carousel.scss 133:34 @import
node_modules\buefy\src\scss\buefy.scss 4:9 @import
src\styles\_main.scss 88:9 root stylesheet
at Object._newRenderError (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:13472:19)
at Object._wrapException (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:13315:16)
at StaticClosure._renderSync (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:13290:18)
at Object.Primitives_applyFunction (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:1085:30)
at Object.Function_apply (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:6003:16)
at _callDartFunctionFast (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:7672:16)
at Object.renderSync (C:\Code\StyleTest\test-styles\node_modules\sass\sass.dart.js:7650:18)
at Object.renderSass (C:\Code\StyleTest\test-styles\node_modules\bulma-css-vars\dist\render-sass.js:7:27)
at C:\Code\StyleTest\test-styles\node_modules\bulma-css-vars\dist\cli.js:90:43
at Generator.next (<anonymous>)
(node:17312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17312) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
//bulma-css-vars.config.js
`const { hsl } = require('bulma-css-vars')
// color names have to match bulma's $variable-name, without '$'
// values will be used for initial colors and fallback
const appColors = {
primary: hsl(161, 49, 58),
secondary: hsl(355, 52, 48),
tertiary: hsl(32, 100, 93),
}
// reuse variable colors
appColors['text'] = appColors['primary']
module.exports = {
sassEntryFile: './src/styles/_main.scss',
jsOutputFile: './src/bulma-generated/bulma-colors.js',
sassOutputFile: './src/bulma-generated/generated-vars.sass',
cssFallbackOutputFile: './src/bulma-generated/generated-fallbacks.css',
colorDefs: appColors,
globalWebVar: false,
transition: '0.5s ease',
}`
//_main.scss
`// import fallbacks first, so they are overridden
@import '../bulma-generated/generated-fallback.css';
@import '../bulma-generated/generated-vars.sass';
@import 'node_modules/bulma-css-vars/bulma-cv-lib';
// Import Bulma's core
@import "node_modules/bulma/sass/utilities/_all";
// I intend to customise Buefy/Bulma here
// Import Bulma and Buefy styles
@import "node_modules/bulma/bulma";
@import "node_modules/buefy/src/scss/buefy";`
Hello,
I'm new to Javascript, so it is probably my problem, but I've spent a few evenings on this and wasn't able to google anything related, so here I am asking for help.
I have a simple Vue app with CSS handled by bulma
. Here is a color picker and a function to change the primary
color in bulma
using bulma-css-vars
:
<script setup lang="ts">
import { ColorUpdater } from 'bulma-css-vars';
import { ColorCallSet } from "bulma-css-vars/dist/types";
import { bulmaCssVariablesDefs } from "../bulma-generated/bulma-colors";
const colorUpdater = new ColorUpdater(bulmaCssVariablesDefs as ColorCallSet);
function setPrimaryColor(event: any) {
const colorName = "primary";
const color = event.target.value;
colorUpdater.updateVarsInDocument(colorName, color);
}
</script>
<template>
<div class="content">
<label>Primary
<input
type="color"
@change="setPrimaryColor"
class="input is-primary"
/>
</label>
</div>
</template>
However, calling the setPrimaryColor
function (when the <input>
element value is changed or even calling colorUpdater.updateVarsInDocument(...)
manually) causes the following error.
Uncaught TypeError: Color is not a function
at stringToHsl (bulma-color-tools.js:90:30)
at ColorUpdater.getUpdatedVars (color-updater.js:24:23)
at ColorUpdater.updateVarsInDocument (color-updater.js:33:31)
at setPrimaryColor (ColorPalette.vue:13:16)
at callWithErrorHandling (runtime-core.esm-bundler.js:157:22)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:166:21)
at HTMLInputElement.invoker (runtime-dom.esm-bundler.js:345:9)
bulma-css-vars/lib/src/bulma-color-tools.ts
Line 125 in 6a669dc
export function stringToHsl(col) {
const [h, s, l] = getHsl(Color(col)).color; // <<<< HERE IS THE ERROR THROWN IN Color(col)
return { h, s, l };
}
I tried debugging in Chrome and playing with the Color
object. My findings are here:
typeof Color: "object"
Color: Function
col: "#520f0f"
Color(col): <not available>
Color.default(col): Color2
Color.prototype(col): <not available>
Color('rgb(123,123,123)'): <not available>
Color({r:123, g:123, b:123}): <not available>
new Color(col): <not available>
Color.call(col): <not available>
I believe that Color.default(col)
does the expected thing in my environment.
Could I have a different version of something? My package-lock.js
says:
"node_modules/bulma": {
"version": "0.9.4",
"resolved": "https://registry.npmjs.org/bulma/-/bulma-0.9.4.tgz",
"integrity": "sha512-86FlT5+1GrsgKbPLRRY7cGDg8fsJiP/jzTqXXVqiUZZ2aZT8uemEOHlU1CDU+TxklPEZ11HZNNWclRBBecP4CQ=="
},
"node_modules/bulma-css-vars": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/bulma-css-vars/-/bulma-css-vars-0.8.0.tgz",
"integrity": "sha512-PhhvuZcSPlnPvgWoo/8y8QAYHCCkW2gjCcVD5P/zIyNrKwzk+I4QdDpexKtzCF7TduNNP5DQGG8InulBe5TGtg==",
"dev": true,
"dependencies": {
"color": "^4.2.1",
"css": "^3.0.0",
"mkdirp": "^1.0.4"
},
"bin": {
"bulma-css-vars": "bin/bulma-css-vars.js"
},
"engines": {
"node": ">= 10.0.0"
},
"peerDependencies": {
"bulma": "^0.9.3"
}
},
"node_modules/color": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
"integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==",
"dev": true,
"dependencies": {
"color-convert": "^2.0.1",
"color-string": "^1.9.0"
},
"engines": {
"node": ">=12.5.0"
}
},
And my package.json
:
"dependencies": {
"@fortawesome/fontawesome-free": "^6.2.1",
"@pinia/testing": "^0.0.14",
"@vueuse/core": "^7.7.0",
"axios": "^0.26.0",
"bulma": "^0.9.3",
"pinia": "^2.0.11",
"vue": "^3.2.31",
"vue-router": "^4.0.13"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.2.4",
"bulma-css-vars": "^0.8.0",
"cypress": "^12.1.0",
"eslint-plugin-cypress": "^2.12.1",
"sass": "^1.49.9",
"typescript": "^4.6.2",
"vite": "^2.8.5",
"vue-tsc": "^0.32.0"
}
I am stuck at --init step with this output
D:\c#\c#projects\test2>node ./node_modules/.bin/bulma-css-vars --init
D:\c#\c#projects\test2\node_modules\.bin\bulma-css-vars:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
โ[90m at wrapSafe (internal/modules/cjs/loader.js:979:16)โ[39m
โ[90m at Module._compile (internal/modules/cjs/loader.js:1027:27)โ[39m
โ[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)โ[39m
โ[90m at Module.load (internal/modules/cjs/loader.js:928:32)โ[39m
โ[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)โ[39m
โ[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)โ[39m
โ[90m at internal/main/run_main_module.js:17:47โ[39m
package.json
{
"name": "topas4analyticsweb",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"css-build": "sass src/main.csss src/assets/css/main.css",
"css-watch": "npm run css-build -- --watch",
"start": "npm run css-watch"
},
"dependencies": {
"@adapttive/vue-markdown": "^4.0.1",
"@diracleo/vue-enlargeable-image": "0.0.7",
"buefy": "^0.9.8",
"bulma": "^0.9.3",
"bulma-css-vars": "^0.6.1",
"core-js": "^3.6.5",
"lodash": "^4.17.21",
"markdown-it-vue": "^1.1.6",
"plotly.js": "^2.2.1",
"vue": "^2.6.11",
"vue-clipboard2": "^0.3.1",
"vue-luxon": "^0.10.0",
"vue-router": "^3.2.0",
"vue-select": "^3.11.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "^4.5.13",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.35.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/strongly-recommended",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"no-mixed-spaces-and-tabs": "off",
"vue/require-v-for-key": "off",
"no-unused-vars": [
"error",
{
"args": "none"
}
]
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Hi again,
I'm currently trying to build an app with a dynamic customisable theme. Currently, it has a three colours, two of which I have added to Bulma via scss (i.e. $secondary & $tertiary), which allows me to use the classes 'is-secondary', 'is-tertiary', etc
I'd like to include these 'custom' colours in the "generated-vars.scss" file, but I can't get my head around your source code.
Could you direct me to which areas I should be looking at?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.