Skip to content

Commit b2443a0

Browse files
committed
docs: update documentation
1 parent 94ce788 commit b2443a0

File tree

11 files changed

+793
-14
lines changed

11 files changed

+793
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: CSS variables
3+
name: CSS variables
4+
description: Use CoreUI's CSS custom properties for fast and forward-looking design and development.
5+
menu: Templates
6+
route: /templates/css-variables
7+
---
8+
9+
CoreUI includes around two dozen [CSS custom properties (variables)](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) in its compiled CSS, with dozens more on the way for improved customization on a per-component basis. These provide easy access to commonly used values like our theme colors, breakpoints, and primary font stacks when working in your browser's inspector, a code sandbox, or general prototyping.
10+
11+
**All our custom properties are prefixed with `cui-`** to avoid conflicts with third party CSS.
12+
13+
## Root variables
14+
15+
Here are the variables we include (note that the `:root` is required) that can be accessed anywhere CoreUI's CSS is loaded. They're located in our `_root.scss` file and included in our compiled dist files.
16+
17+
```css
18+
:root {
19+
--cui-blue: #0d6efd;
20+
--cui-indigo: #6610f2;
21+
--cui-purple: #6f42c1;
22+
--cui-pink: #d63384;
23+
--cui-red: #dc3545;
24+
--cui-orange: #fd7e14;
25+
--cui-yellow: #ffc107;
26+
--cui-green: #198754;
27+
--cui-teal: #20c997;
28+
--cui-cyan: #0dcaf0;
29+
--cui-black: #000015;
30+
--cui-white: #fff;
31+
--cui-gray: #8a93a2;
32+
--cui-gray-dark: #636f83;
33+
--cui-gray-100: #ebedef;
34+
--cui-gray-200: #d8dbe0;
35+
--cui-gray-300: #c4c9d0;
36+
--cui-gray-400: #b1b7c1;
37+
--cui-gray-500: #9da5b1;
38+
--cui-gray-600: #8a93a2;
39+
--cui-gray-700: #768192;
40+
--cui-gray-800: #636f83;
41+
--cui-gray-900: #4f5d73;
42+
--cui-primary: #321fdb;
43+
--cui-secondary: #9da5b1;
44+
--cui-success: #2eb85c;
45+
--cui-info: #39f;
46+
--cui-warning: #f9b115;
47+
--cui-danger: #e55353;
48+
--cui-light: #ebedef;
49+
--cui-dark: #4f5d73;
50+
--cui-primary-rgb: 50, 31, 219;
51+
--cui-secondary-rgb: 157, 165, 177;
52+
--cui-success-rgb: 46, 184, 92;
53+
--cui-info-rgb: 51, 153, 255;
54+
--cui-warning-rgb: 249, 177, 21;
55+
--cui-danger-rgb: 229, 83, 83;
56+
--cui-light-rgb: 235, 237, 239;
57+
--cui-dark-rgb: 79, 93, 115;
58+
--cui-white-rgb: 255, 255, 255;
59+
--cui-black-rgb: 0, 0, 21;
60+
--cui-body-color-rgb: 44, 56, 74;
61+
--cui-body-bg-rgb: 255, 255, 255;
62+
--cui-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
63+
--cui-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
64+
--cui-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
65+
--cui-body-font-family: var(--cui-font-sans-serif);
66+
--cui-body-font-size: 1rem;
67+
--cui-body-font-weight: 400;
68+
--cui-body-line-height: 1.5;
69+
--cui-body-color: rgba(44, 56, 74, 0.95);
70+
--cui-body-bg: #fff;
71+
--cui-border-width: 1px;
72+
--cui-border-style: solid;
73+
--cui-border-color: #d8dbe0;
74+
--cui-border-color-translucent: rgba(0, 0, 21, 0.175);
75+
--cui-border-radius: 0.375rem;
76+
--cui-border-radius-sm: 0.25rem;
77+
--cui-border-radius-lg: 0.5rem;
78+
--cui-border-radius-xl: 1rem;
79+
--cui-border-radius-2xl: 2rem;
80+
--cui-border-radius-pill: 50rem;
81+
--cui-heading-color: unset;
82+
--cui-link-color: #321fdb;
83+
--cui-link-hover-color: #2819af;
84+
--cui-code-color: #d63384;
85+
--cui-highlight-bg: #fff3cd;
86+
}
87+
```
88+
89+
## Component variables
90+
91+
CoreUI is increasingly making use of custom properties as local variables for various components. This way we reduce our compiled CSS, ensure styles aren't inherited in places like nested tables, and allow some basic restyling and extending of CoreUI components after Sass compilation.
92+
93+
Whenever possible, we'll assign CSS variables at the base component level (e.g., `.navbar` for navbar and its sub-components). This reduces guessing on where and how to customize, and allows for easy modifications by our team in future updates.
94+
95+
## Prefix
96+
97+
Most CSS variables use a prefix to avoid collisions with your own codebase. This prefix is in addition to the `--` that's required on every CSS variable.
98+
99+
Customize the prefix via the `$prefix` Sass variable. By default, it's set to `cui-` (note the trailing dash).
100+
101+
## Examples
102+
103+
CSS variables offer similar flexibility to Sass's variables, but without the need for compilation before being served to the browser. For example, here we're resetting our page's font and link styles with CSS variables.
104+
105+
```css
106+
body {
107+
font: 1rem/1.5 var(--cui-font-sans-serif);
108+
}
109+
a {
110+
color: var(--cui-blue);
111+
}
112+
```
113+
114+
## Grid breakpoints
115+
116+
While we include our grid breakpoints as CSS variables (except for `xs`), be aware that **CSS variables do not work in media queries**. This is by design in the CSS spec for variables, but may change in coming years with support for `env()` variables. Check out [this Stack Overflow answer](https://stackoverflow.com/a/47212942) for some helpful links. In the mean time, you can use these variables in other CSS situations, as well as in your JavaScript.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Options
3+
description: Quickly customize CoreUI for React with built-in variables to easily toggle global CSS preferences for controlling style and behavior.
4+
menu: Customize
5+
route: /customize/options
6+
---
7+
8+
Customize CoreUI for React with our built-in custom variables file and easily toggle global CSS preferences with new `$enable-*` Sass variables. Override a variable's value and recompile with `npm run test` as needed.
9+
10+
You can find and customize these variables for key global options in CoreUI's `@coreui/coreui/scss/_variables.scss` file.
11+
12+
| Variable | Values | Description |
13+
| ------------------------------ | ---------------------------------- | -------------------------------------------------------------------------------------- |
14+
| `$spacer` | `1rem` (default), or any value > 0 | Specifies the default spacer value to programmatically generate our [spacer utilities]({{< docsref "/utilities/spacing" >}}). |
15+
| `$enable-rounded` | `true` (default) or `false` | Enables predefined `border-radius` styles on various components. |
16+
| `$enable-shadows` | `true` or `false` (default) | Enables predefined decorative `box-shadow` styles on various components. Does not affect `box-shadow`s used for focus states. |
17+
| `$enable-gradients` | `true` or `false` (default) | Enables predefined gradients via `background-image` styles on various components. |
18+
| `$enable-transitions` | `true` (default) or `false` | Enables predefined `transition`s on various components. |
19+
| `$enable-reduced-motion` | `true` (default) or `false` | Enables the [`prefers-reduced-motion` media query]({{< docsref "/getting-started/accessibility#reduced-motion" >}}), which suppresses certain animations/transitions based on the users' browser/operating system preferences. |
20+
| `$enable-grid-classes` | `true` (default) or `false` | Enables the generation of CSS classes for the grid system (e.g. `.row`, `.col-md-1`, etc.). |
21+
| `$enable-container-classes` | `true` (default) or `false` | Enables the generation of CSS classes for layout containers. (New in v4.2.0) |
22+
| `$enable-caret` | `true` (default) or `false` | Enables pseudo element caret on `.dropdown-toggle`. |
23+
| `$enable-button-pointers` | `true` (default) or `false` | Add "hand" cursor to non-disabled button elements. |
24+
| `$enable-rfs` | `true` (default) or `false` | Globally enables [RFS]({{< docsref "/getting-started/rfs" >}}). |
25+
| `$enable-validation-icons` | `true` (default) or `false` | Enables `background-image` icons within textual inputs and some custom forms for validation states. |
26+
| `$enable-negative-margins` | `true` or `false` (default) | Enables the generation of [negative margin utilities]({{< docsref "/utilities/spacing#negative-margin" >}}). |
27+
| `$enable-deprecation-messages` | `true` (default) or `false` | Set to `false` to hide warnings when using any of the deprecated mixins and functions that are planned to be removed in `v6`. |
28+
| `$enable-important-utilities` | `true` (default) or `false` | Enables the `!important` suffix in utility classes. |
29+
| `$enable-smooth-scroll` | `true` (default) or `false` | Applies `scroll-behavior: smooth` globally, except for users asking for reduced motion through [`prefers-reduced-motion` media query]({{< docsref "/getting-started/accessibility#reduced-motion" >}}) |
30+
| `$enable-ltr` | `false` or `false` (default) | Enables Left-to-Right |
31+
| `$enable-rtl` | `true` (default) or `false` | Enables Right-to-Left |
32+

0 commit comments

Comments
 (0)