@carbon/themes 10.38.0-rc.0 → 10.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -93,6 +93,12 @@ import {
93
93
  } from '@carbon/themes';
94
94
  ```
95
95
 
96
+ ## 📖 API Documentation
97
+
98
+ If you're looking for `@carbon/themes` API documentation, check out:
99
+
100
+ - [Sass](./docs/sass.md)
101
+
96
102
  ## 📚 Examples
97
103
 
98
104
  If you're looking for more examples on how to use `@carbon/themes`, we have some
package/docs/sass.md ADDED
@@ -0,0 +1,96 @@
1
+ # `@carbon/themes`
2
+
3
+ _Note: this documentation is used with the next version of `@carbon/themes`
4
+ which uses Sass Modules. It will not work in the current stable version of this
5
+ package_
6
+
7
+ <!-- prettier-ignore-start -->
8
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
9
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
10
+ ## Table of Contents
11
+
12
+ - [Usage](#usage)
13
+ - [FAQ](#faq)
14
+ - [Why are the themes not exported in `@carbon/themes`?](#why-are-the-themes-not-exported-in-carbonthemes)
15
+
16
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
17
+ <!-- prettier-ignore-end -->
18
+
19
+ ## Usage
20
+
21
+ There are several entrypoints that you can use with `@carbon/themes`, including:
22
+
23
+ | Filename | Description |
24
+ | -------------------------------------------- | ------------------------------------------------------ |
25
+ | `@use '@carbon/themes';` | Package entrypoint |
26
+ | `@use '@carbon/themes/scss/modules/config';` | Specify config options for the package |
27
+ | `@use '@carbon/themes/scss/modules/themes';` | Theme definitions for white, g10, g90, and g100 |
28
+ | `@use '@carbon/themes/scss/modules/theme';` | Set the current theme, get token values from the theme |
29
+ | `@use '@carbon/themes/scss/modules/tokens';` | Access theme tokens |
30
+
31
+ _Note: the white, g10, g90, and g100 themes are only available in the
32
+ `scss/modules/themes` file and are not re-exported in `@carbon/themes`. To learn
33
+ more, checkout our [FAQ](#why-are-the-themes-not-exported-in-carbonthemes)._
34
+
35
+ You can bring in `@carbon/themes` by using `@use`:
36
+
37
+ ```scss
38
+ @use '@carbon/themes';
39
+
40
+ .my-component {
41
+ // Use tokens from the theme, this will map to a CSS Custom Property
42
+ color: themes.$token-01;
43
+ }
44
+
45
+ :root {
46
+ // Emit CSS Custom Properties for the current theme
47
+ @include themes.theme();
48
+ }
49
+
50
+ // Get the value of a specific token
51
+ $custom-variable: rgba(themes.get('token-01'), 0.25);
52
+ ```
53
+
54
+ You can configure the current theme with the `$theme` option:
55
+
56
+ ```scss
57
+ @use '@carbon/themes/scss/modules/themes';
58
+ @use '@carbon/themes' with (
59
+ $theme: themes.$g100,
60
+ );
61
+ ```
62
+
63
+ You can also extend the theme with your own custom tokens:
64
+
65
+ ```scss
66
+ @use '@carbon/themes/scss/modules/themes';
67
+ @use '@carbon/themes' with (
68
+ $fallback: themes.$g100,
69
+ $theme: (
70
+ token-01: #000000,
71
+ ),
72
+ );
73
+ ```
74
+
75
+ ## Tokens
76
+
77
+ TODO
78
+
79
+ ## FAQ
80
+
81
+ ### Why are the themes not exported in `@carbon/themes`?
82
+
83
+ In order to support `@use '@carbon/themes' with` in Sass Modules, unfortunately
84
+ we cannot re-export the themes available in `scss/modules/themes`. If we
85
+ implemented the entrypoint at `@carbon/themes` to re-export that module, then
86
+ Sass would not compile when doing the following:
87
+
88
+ ```scss
89
+ @use '@carbon/themes/scss/modules/themes';
90
+ @use '@carbon/themes' with (
91
+ $theme: themes.$g100,
92
+ );
93
+ ```
94
+
95
+ This is because the `scss/modules/themes` file will have been initialized twice
96
+ which is not allowed in the Sass Module system.
package/index.scss CHANGED
@@ -5,6 +5,6 @@
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  //
7
7
 
8
- @forward 'scss/modules/themes';
8
+ @forward 'scss/modules/config';
9
9
  @forward 'scss/modules/theme';
10
10
  @forward 'scss/modules/tokens';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/themes",
3
3
  "description": "Themes for applying color in the Carbon Design System",
4
- "version": "10.38.0-rc.0",
4
+ "version": "10.39.1",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -26,16 +26,18 @@
26
26
  "scripts": {
27
27
  "ci-check": "carbon-cli check \"scss/**/*.scss\" -i \"**/generated/**\"",
28
28
  "clean": "rimraf es lib umd scss/generated",
29
- "build": "yarn clean && carbon-cli bundle src/index.js --name CarbonThemes && node tasks/build.js && carbon-cli check \"scss/*.scss\""
29
+ "build": "yarn clean && carbon-cli bundle src/index.js --name CarbonThemes && babel-node --presets '@babel/preset-env' tasks/build.js && carbon-cli check \"scss/*.scss\""
30
30
  },
31
31
  "dependencies": {
32
- "@carbon/colors": "^10.28.0-rc.0",
33
- "@carbon/layout": "^10.27.0-rc.0",
34
- "@carbon/type": "^10.31.0-rc.0",
32
+ "@carbon/colors": "^10.29.1",
33
+ "@carbon/layout": "^10.28.0",
34
+ "@carbon/type": "^10.32.1",
35
35
  "color": "^3.1.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@carbon/cli": "^10.25.0",
38
+ "@babel/node": "^7.14.2",
39
+ "@babel/preset-env": "^7.14.2",
40
+ "@carbon/cli": "^10.26.0",
39
41
  "@carbon/cli-reporter": "^10.5.0",
40
42
  "@carbon/scss-generator": "^10.13.0",
41
43
  "@carbon/test-utils": "^10.16.0",
@@ -46,5 +48,6 @@
46
48
  "node-sass": "^4.13.1",
47
49
  "rimraf": "^3.0.0"
48
50
  },
49
- "gitHead": "49e427c7756fd928db99b0d201928b87d4ab2c71"
51
+ "sideEffects": false,
52
+ "gitHead": "51b7bce591d08798445927dec8a91436bfd31c57"
50
53
  }
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright IBM Corp. 2018, 2018
3
+ //
4
+ // This source code is licensed under the Apache-2.0 license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ //
7
+
8
+ $prefix: 'cds' !default;
@@ -7,18 +7,23 @@
7
7
 
8
8
  @use 'sass:map';
9
9
  @use 'sass:meta';
10
+ @use 'config';
10
11
  @use 'themes';
11
12
 
12
- $theme: themes.$white !default;
13
- $-custom-property-prefix: 'cds';
13
+ /// Specify the fallback theme, used as a catch-all for tokens that you may not
14
+ /// have defined in your custom theme
15
+ $fallback: themes.$white !default;
14
16
 
15
- /// @access public
16
- /// @group @carbon/themes
17
- @mixin theme($active-theme: $theme, $component-tokens...) {
18
- $parent-theme: $theme;
19
- $theme: $active-theme !global;
17
+ /// Specify the current theme. This can override existing tokens, or add new
18
+ /// tokens. If you are adding new tokens, it's recommended that you set the
19
+ /// fallback for your current theme
20
+ $theme: () !default;
21
+ $theme: map.merge($fallback, $theme);
20
22
 
21
- @each $token, $value in $theme {
23
+ /// Include the CSS Custom Properties for the active theme or a given theme on
24
+ /// a selector
25
+ @mixin theme($active-theme: $theme, $component-tokens...) {
26
+ @each $token, $value in $active-theme {
22
27
  @include -custom-property($token, $value);
23
28
  }
24
29
 
@@ -27,21 +32,20 @@ $-custom-property-prefix: 'cds';
27
32
  @include -custom-property($token, $value);
28
33
  }
29
34
  }
30
-
31
- @content;
32
-
33
- $theme: $parent-theme !global;
34
35
  }
35
36
 
36
- /// @access public
37
- /// @group @carbon/themes
38
- @mixin set-theme($active-theme) {
39
- $theme: $active-theme !global;
37
+ /// Retrieve the value for the given $token from the current $theme
38
+ /// @param {String} $token
39
+ @function get($token) {
40
+ @if map.has-key($theme, $token) {
41
+ @return map.get($theme, $token);
42
+ }
43
+ @error "Unable to find token: #{$token} in current $theme";
40
44
  }
41
45
 
42
46
  /// @access private
43
47
  /// @group @carbon/themes
44
- @mixin -custom-property($name, $value, $prefix: $-custom-property-prefix) {
48
+ @mixin -custom-property($name, $value) {
45
49
  @if meta.type-of($value) == map {
46
50
  @each $property, $property-value in $value {
47
51
  // Only support one-level of depth for values that are maps. This is to
@@ -51,6 +55,6 @@ $-custom-property-prefix: 'cds';
51
55
  }
52
56
  }
53
57
  } @else {
54
- --#{$prefix}-#{$name}: #{$value};
58
+ --#{config.$prefix}-#{$name}: #{$value};
55
59
  }
56
60
  }
@@ -6,3 +6,4 @@
6
6
  //
7
7
 
8
8
  @forward 'generated/themes';
9
+ @use 'generated/themes';