Skip to content

Commit

Permalink
feat: add @cds/core shim
Browse files Browse the repository at this point in the history
This commit copies the shim from `@cds/core@6.2.5` to `@clr/ui`.

We are moving the shim to the `@clr/ui` package to allow both to be
evolved together. Otherwise, changes to the custom property API exposed
by `@clr/ui` will require changes in a separate package (and separate repo).
This would cause version synchronization difficulties.

How to update:

The file path in applications should be updated as follows:
'@cds/core/styles/shim.clr-ui.min.css' -> '@clr/ui/shim.cds-core.min.css'

That's it, just a simple find and replace.
  • Loading branch information
kevinbuhmann committed Feb 1, 2023
1 parent 9436eab commit c7c51e5
Show file tree
Hide file tree
Showing 6 changed files with 853 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ module.exports = {
trailingComma: 'es5',
bracketSpacing: true,
arrowParens: 'avoid',
overrides: [
{
files: 'projects/ui/src/shim.cds-core.scss',
options: {
printWidth: 200,
},
},
],
};
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = {
stories: ['./stories/**/*.stories.{ts,mdx}'],
stories: ['./**/*.stories.{ts,mdx}'],
addons: ['@storybook/addon-essentials', '@storybook/addon-a11y'],
framework: '@storybook/angular',
core: {
Expand Down
42 changes: 42 additions & 0 deletions .storybook/pages/cds-core-shim.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Meta } from '@storybook/addon-docs';

<Meta title="cds-core shim" />

# @cds/core shim

Clarity provides a theme the enables `@clr/ui` applications to consume the Clarity Core design
tokens and theme system. Once installed, `@clr/ui` applications will be able to use all Clarity Core
color themes available today, in particular the color contrast adjustments in the light and dark
themes. The shim maps colors to the `@cds/core` design token system. Typography and spacing are
not affected. If your application does not use `@clr/ui`, this shim is not needed.

Follow the [Getting Started](https://storybook.core.clarity.design/?path=/story/documentation-getting-started--page)
directions for Clarity Core, including loading the relevant CSS files and setting the `cds-theme`
attribute on the body tag. The shim will not be applied to `@clr/ui` or `@clr/angular` components
without this attribute.

Import and load the CSS shim file last after `@clr/ui` global CSS. This will ensure that the shim can
override the `@clr/ui` values appropriately.

```css
@import 'modern-normalize/modern-normalize.css';
@import '@cds/core/global.min.css'; // provides the Clarity Core design tokens
@import '@cds/core/styles/theme.dark.min.css'; // to allow dark mode with cds-theme="dark"
@import '@clr/ui/clr-ui.min.css'; // @clr/ui CSS (this should already be imported by your application)
@import '@cds/ui/shim.cds-core.min.css'; // the shim file
```

## Dark Mode

Clarity Core's dark mode should replace the `@clr/ui` dark mode. Remove any reference to the `@clr/ui`
dark mode file from the source code and toggle dark mode by changing the `cds-theme` attribute to "dark."

## Adoption

We fully support the `@cds/core` shim as the path forward for ng-clarity. But we need your help. The
shim is currently optional, but the only way to improve the Shim is to get feedback from teams as
they adopt it in their projects/products. We recomend new projects to use the shim from the start.
For existing projects, we ask teams to start adopting it to help us test it and provide feedback.

Our goal is mature the shim to a point where it can be the default (and later the only) option for
theming Clarity.
2 changes: 1 addition & 1 deletion .storybook/public/preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
@import '@cds/core/styles/module.typography.min.css';
@import '@cds/core/styles/theme.dark.min.css';
@import '@cds/core/styles/theme.high-contrast.min.css';
@import '@cds/core/styles/shim.clr-ui.min.css';
@import '../../dist/clr-ui/shim.cds-core.css';
2 changes: 1 addition & 1 deletion projects/demo/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@import '@cds/core/styles/module.typography.min.css';
@import '@cds/core/styles/theme.dark.min.css';
@import '@cds/core/styles/theme.high-contrast.min.css';
@import '@cds/core/styles/shim.clr-ui.min.css';
@import './../../ui/src/shim.cds-core';
@import './app/_utils/clarity-variables';
@import '../../angular/src/utils/variables/variables';

Expand Down
Loading

0 comments on commit c7c51e5

Please sign in to comment.