Skip to content

Commit 573bb99

Browse files
committed
update docs table while here
1 parent 4441dd6 commit 573bb99

1 file changed

Lines changed: 34 additions & 35 deletions

File tree

  • site/src/content/docs/utilities

site/src/content/docs/utilities/api.mdx

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,22 @@ aliases: "/docs/[[config:docs_version]]/utilities/"
55
toc: true
66
---
77

8-
Bootstrap utilities are generated with our utility API and can be used to modify or extend our default set of utility classes via Sass. Our utility API is based on a series of Sass maps and functions for generating families of classes with various options. If youre unfamiliar with Sass maps, read up on the [official Sass docs](https://sass-lang.com/documentation/values/maps/) to get started.
8+
Bootstrap utilities are generated with our utility API and can be used to modify or extend our default set of utility classes via Sass. Our utility API is based on a series of Sass maps and functions for generating families of classes with various options. If you're unfamiliar with Sass maps, read up on the [official Sass docs](https://sass-lang.com/documentation/values/maps/) to get started.
99

1010
The `$utilities` map contains all our utilities and is later merged with your custom `$utilities` map, if present. The utility map contains a keyed list of utility groups which accept the following options:
1111

1212
<BsTable class="table table-utilities">
1313
| Option | Type | Default&nbsp;value | Description |
1414
| --- | --- | --- | --- |
15-
| [`property`](#property) | **Required** || Name of the property, this can be a string or an array of strings (e.g., horizontal paddings or margins). |
15+
| [`property`](#property) | **Required** || Name of the property, this can be a string or an array of strings (e.g., horizontal paddings or margins). Can also be a map for [property-value mapping](#property-value-mapping). |
1616
| [`values`](#values) | **Required** || List of values, or a map if you don't want the class name to be the same as the value. If `null` is used as map key, `class` is not prepended to the class name. |
17-
| [`selector`](#selector) | Optional | `class` | Type of CSS selector in the generated CSS ruleset. Can be `class`, `attr-starts`, or `attr-includes`. |
17+
| [`selector`](#selector) | Optional | `class` | Type of CSS selector in the generated CSS ruleset. Must be `class`, `attr-starts`, or `attr-includes`. Attribute selectors require the `class` option. |
1818
| [`class`](#class) | Optional | null | Name of the generated class. If not provided and `property` is an array of strings, `class` will default to the first element of the `property` array. If not provided and `property` is a string, the `values` keys are used for the `class` names. |
19-
| [`css-var`](#css-variable-utilities) | Optional | `false` | Boolean to generate CSS variables instead of CSS rules. |
20-
| [`css-variable-name`](#css-variable-utilities) | Optional | null | Custom un-prefixed name for the CSS variable inside the ruleset. |
21-
| [`local-vars`](#local-css-variables) | Optional | null | Map of local CSS variables to generate in addition to the CSS rules. |
19+
| [`variables`](#variables) | Optional | null | List or map of local CSS variables to generate within the utility's ruleset. If a list, each variable receives the utility value. If a map, uses the provided static values. |
2220
| [`state`](#states) | Optional | null | List of pseudo-class variants (e.g., `:hover` or `:focus`) to generate. |
2321
| [`responsive`](#responsive) | Optional | `false` | Boolean indicating if responsive classes should be generated. |
2422
| [`important`](#importance) | Optional | `false` | Boolean indicating if `!important` should be added to the utility's CSS rules. |
2523
| [`print`](#print) | Optional | `false` | Boolean indicating if print classes need to be generated. |
26-
| `rtl` | Optional | `true` | Boolean indicating if utility should be kept in RTL. |
2724
</BsTable>
2825

2926
## API explained
@@ -59,7 +56,7 @@ Which outputs the following:
5956

6057
<div class="badge fs-6 bg-accent mb-3">Required</div>
6158

62-
The `property` key must be set for any utility, and it must contain a valid CSS property. This property is used in the generated utilitys ruleset. When the `class` key is omitted, it also serves as the default class name. Consider the `text-decoration` utility:
59+
The `property` key must be set for any utility, and it must contain a valid CSS property. This property is used in the generated utility's ruleset. When the `class` key is omitted, it also serves as the default class name. Consider the `text-decoration` utility:
6360

6461
```scss
6562
$utilities: (
@@ -208,18 +205,20 @@ Output:
208205
.invisible { visibility: hidden; }
209206
```
210207

211-
### CSS variable utilities
208+
### Variables
212209

213-
Set the `css-var` boolean option to `true` and the API will generate local CSS variables for the given selector instead of the usual `property: value` rules. Add an optional `css-variable-name` to set a different CSS variable name than the class name.
210+
Use the `variables` option to generate local CSS custom properties within the utility's ruleset. It accepts either a list or a map.
214211

215-
Consider our `.text-opacity-*` utilities. If we add the `css-variable-name` option, we'll get a custom output.
212+
When `variables` is a **list**, each variable receives the current utility value:
216213

217214
```scss
218215
$utilities: (
219-
"text-opacity": (
220-
css-var: true,
221-
css-variable-name: text-alpha,
222-
class: text-opacity,
216+
"opacity": (
217+
property: opacity,
218+
class: opacity,
219+
variables: (
220+
"opacity-value"
221+
),
223222
values: (
224223
25: .25,
225224
50: .5,
@@ -233,29 +232,29 @@ $utilities: (
233232
Output:
234233

235234
```css
236-
.text-opacity-25 { --bs-text-alpha: .25; }
237-
.text-opacity-50 { --bs-text-alpha: .5; }
238-
.text-opacity-75 { --bs-text-alpha: .75; }
239-
.text-opacity-100 { --bs-text-alpha: 1; }
235+
.opacity-25 {
236+
--opacity-value: .25;
237+
opacity: .25;
238+
}
239+
.opacity-50 {
240+
--opacity-value: .5;
241+
opacity: .5;
242+
}
243+
/* ... */
240244
```
241245

242-
### Local CSS variables
243-
244-
Use the `local-vars` option to specify a Sass map that will generate local CSS variables within the utility class’s ruleset. Please note that it may require additional work to consume those local CSS variables in the generated CSS rules. For example, consider our `.bg-*` utilities:
246+
When `variables` is a **map**, the provided static values are used instead:
245247

246248
```scss
247249
$utilities: (
248250
"background-color": (
249251
property: background-color,
250252
class: bg,
251-
local-vars: (
253+
variables: (
252254
"bg-opacity": 1
253255
),
254-
values: map-merge(
255-
$utilities-bg-colors,
256-
(
257-
"transparent": transparent
258-
)
256+
values: (
257+
primary: var(--primary),
259258
)
260259
)
261260
);
@@ -265,14 +264,14 @@ Output:
265264

266265
```css
267266
.bg-primary {
268-
--bs-bg-opacity: 1;
269-
background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity));
267+
--bg-opacity: 1;
268+
background-color: var(--primary);
270269
}
271270
```
272271

273272
### States
274273

275-
Use the `state` option to generate pseudo-class variations. Example pseudo-classes are `:hover` and `:focus`. When a list of states are provided, classnames are created for that pseudo-class. For example, to change opacity on hover, add `state: hover` and youll get `.opacity-hover:hover` in your compiled CSS.
274+
Use the `state` option to generate pseudo-class variations. Example pseudo-classes are `:hover` and `:focus`. When a list of states are provided, classnames are created for that pseudo-class. For example, to change opacity on hover, add `state: hover` and you'll get `.opacity-hover:hover` in your compiled CSS.
276275

277276
Need multiple pseudo-classes? Use a space-separated list of states: `state: hover focus`.
278277

@@ -445,7 +444,7 @@ Some utilities like `display`, `position`, and `visibility` have `important: tru
445444

446445
## Using the API
447446

448-
Now that youre familiar with how the utilities API works, learn how to add your own custom classes and modify our default utilities.
447+
Now that you're familiar with how the utilities API works, learn how to add your own custom classes and modify our default utilities.
449448

450449
### Override utilities
451450

@@ -463,7 +462,7 @@ $utilities: (
463462

464463
### Add utilities
465464

466-
New utilities can be added to the default `$utilities` map with a `map-merge`. Make sure our required Sass files and `_utilities.scss` are imported first, then use the `map-merge` to add your additional utilities. For example, heres how to add a responsive `cursor` utility with three values.
465+
New utilities can be added to the default `$utilities` map with a `map-merge`. Make sure our required Sass files and `_utilities.scss` are imported first, then use the `map-merge` to add your additional utilities. For example, here's how to add a responsive `cursor` utility with three values.
467466

468467
```scss
469468
@import "bootstrap/scss/functions";
@@ -490,7 +489,7 @@ $utilities: map-merge(
490489

491490
### Modify utilities
492491

493-
Modify existing utilities in the default `$utilities` map with `map-get` and `map-merge` functions. In the example below, were adding an additional value to the `width` utilities. Start with an initial `map-merge` and then specify which utility you want to modify. From there, fetch the nested `"width"` map with `map-get` to access and modify the utilitys options and values.
492+
Modify existing utilities in the default `$utilities` map with `map-get` and `map-merge` functions. In the example below, we're adding an additional value to the `width` utilities. Start with an initial `map-merge` and then specify which utility you want to modify. From there, fetch the nested `"width"` map with `map-get` to access and modify the utility's options and values.
494493

495494
```scss
496495
@import "bootstrap/scss/functions";
@@ -640,7 +639,7 @@ $utilities: map-merge(
640639

641640
### Add, remove, modify
642641

643-
You can add, remove, and modify many utilities all at once with the [`map-merge()` Sass function](https://sass-lang.com/documentation/modules/map/#merge). Heres how you can combine the previous examples into one larger map.
642+
You can add, remove, and modify many utilities all at once with the [`map-merge()` Sass function](https://sass-lang.com/documentation/modules/map/#merge). Here's how you can combine the previous examples into one larger map.
644643

645644
```scss
646645
@import "bootstrap/scss/functions";

0 commit comments

Comments
 (0)