How to reuse a CSS variable from WC in my app?
Is your feature request related to a problem? Please describe.
In my mocks, the UI designer asked for a specific border around a table.
ui5-table only have borders on the top and bottom.
I'd like to reuse the ui5-table's border-bottom CSS property for my instance of ui5-table, but how can I get the exact color used while respecting the theming?.
Describe the solution you'd like
I would like to create a class like this (in my app):
.exchange-table {
border: 1px solid var(--ui5-panel-bottom-border-color); /* any variable from WC */
border-radius: .1em;
}
Describe alternatives you've considered
I could fetch the color after the table has rendered via getComputedProperties and set the color via javascript, but this is troublesome and can be prone to errors.
Additional context
I'd like to follow the UI5 WebComponents classes and variables so we can maybe support custom themes in the future.
I am facing a similar problem too
Yeah, we didn't consider this usage so far and have to address it. The reason the CSS variables for the default theme are not included in the <head> is that the styles of the web components come with the default values as fallbacks.
However, this is a valid use case so we have to consider the options:
- add the parameters always as default
- provide an API to add them only when apps require them
option 1. might be too much in case no one is using them option 2. would require an API call
Until we flesh this out, you can use a workaround that implements option 2. (warning: these APIs might change and are really internal). At least that way you can start using the parameters in your code and give any feedback.
import fiori3ThemeProperties from "@ui5/webcomponents/dist/themes/sap_fiori_3/parameters-bundle.css.js";
import { injectThemeProperties } from "@ui5/webcomponents-base/src/theming/StyleInjection.js";
import Bootstrap from "@ui5/webcomponents-base/src/Bootstrap.js";
// inject default CSS custom parameters in head
Bootstrap.boot().then(_ => {
injectThemeProperties(fiori3ThemeProperties);
});
Here is a working example in codesandbox: https://codesandbox.io/s/ui5webcomponents-llzkj
Any feedback before we implement this is welcome.
@pskelin Consider theme designer when defining the solution
With the latest release (1.0.0-rc.5), the CSS variables are always included as a style tag in the head so feel free to use them in your apps.
Please use with caution, as it is still not clearly documented which ones are considered public. It should be safe to reference all variables starting with --sap, the ones starting with --sapUi will be deleted soon, and the component variables should be considered private unless explicitly documented.