-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
743 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
*/ | ||
|
||
export { default as vitalTypography } from './tokens'; | ||
export { TypographyMeta } from './meta'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright © 2023 Johnson & Johnson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export const TypographyMeta = { | ||
categories: { | ||
Type: ['Element'], | ||
Group: ['Typography'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
|
||
export * from './tokenSpec'; | ||
export * from './testing'; | ||
export * from './shadow'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright © 2023 Johnson & Johnson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export const shadow = (component: any, ...rest: any) => component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/vital-examples/src/customizing-design-tokens/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Learn how to Customize Design Tokens | ||
|
||
In this lesson we will learn how to shadow the design elements, these are the base elements for customizing a website, in it we will define colors, fonts, typography and the like. | ||
|
||
## Overview | ||
|
||
In this lesson we will: | ||
|
||
- Shadow the vital colors with [this palette](https://coolors.co/ccfbfe-cdd6dd-cdcacc-cdaca1-cd8987). | ||
- Shadow vital text decoration to customize the font weight | ||
- Shadow H1 and H2 element tokens to use our custom font and it's properties. | ||
|
||
|
||
## Assignment | ||
|
||
First, we'll need to edit the `tailwind.config.js` file to add the custom variable, colors, font and sizes for examples. You can follow [the naming convention from tailwind](https://tailwindcss.com/docs/customizing-colors#naming-your-colors). | ||
Note that we use the `vital-` prefix to define our colors, our tailwind file will look like this | ||
|
||
#### `tailwind.config.js` | ||
```js | ||
module.exports = { | ||
theme: { | ||
colors: { | ||
'vital-primary': { | ||
brand: '<COLOR>', | ||
// ... | ||
}, | ||
// ... | ||
} | ||
} | ||
} | ||
``` | ||
**PS:** With this, the colors should be already overrided. | ||
You can find all vital colors [in here](https://github.com/johnsonandjohnson/Bodiless-JS/blob/main/packages/vital-elements/src/components/Color/tokens/vitalColor.ts). | ||
|
||
Then under the `src/component` folder, we'll create the files with the Components names, in our case, we'll override the `Typography` and `TextDecoration`, so we create theses files. | ||
|
||
### Components | ||
|
||
For the sake of this example, we will two components, which extends the vital components, `TextDecoration` and `Typography` and define our custom tokens, and to shadow them, we'll just export them. | ||
|
||
#### TextDecoration | ||
|
||
The `TextDecoration` class is easier to do, since we just export some tokens with only a class for each tokens, our file will look like this. | ||
|
||
##### `src/component/TextDecoration/tokens/exampleTextDecoration.ts` | ||
```ts | ||
import { asTokenGroup, TextDecorationMeta } from '@bodiless/vital-elements'; | ||
import { vitalTextDecorationBase } from '@bodiless/vital-elements/src/base'; | ||
|
||
export default asTokenGroup(TextDecorationMeta)({ | ||
...vitalTextDecorationBase, | ||
Bold: 'font-black', | ||
}); | ||
|
||
``` | ||
|
||
**PS:** the `asTokenGroup` function creates a group of element tokens that share the same metadata, you can find more information about the Meta domain [here](https://johnsonandjohnson.github.io/Bodiless-JS/#/VitalDesignSystem/Components/VitalElements/Tokens/TokenDomains?id=special-domains). | ||
|
||
In this example we overwrite the the `Bold` token to set a bolder font. | ||
|
||
#### Typography | ||
|
||
For the typography, we will have to do some more work, each typography element should be a instance of `asElementToken`, so we can rely on Domains to help us to define our tokens. Our typography file will be something like this. | ||
|
||
##### `src/component/TextDecoration/tokens/exampleTypography.ts` | ||
```ts | ||
import { asElementToken, vitalColor, vitalFontSize, vitalTextDecoration } from '@bodiless/vital-elements'; | ||
import { vitalTypographyBase } from '@bodiless/vital-elements/src/base'; | ||
|
||
const H2 = asElementToken({ | ||
...vitalTypographyBase.H2, | ||
Core: { | ||
_: as(vitalTextDecoration.ExtraBold, vitalFontSize.XXL) | ||
} | ||
}); | ||
``` | ||
|
||
In this example, we created a custom H1 and H2 Tokens and exporting them with the vital typography base. So our package have all the vital tokens. | ||
|
||
### Shadowing | ||
|
||
And now, to shadow the our tokens, create a file with the same path of the package, in out case, since we area shadowing the `@bodiles/vital-elements` package, we'll have this structure. | ||
|
||
```bash | ||
├── shadow | ||
│ ├── @bodiless | ||
│ │ ├── vital-elements | ||
│ │ | ├─ Typography.ts | ||
│ │ | └─ TextDecoration.ts | ||
``` | ||
|
||
Where each file export the tokens from the components folder. | ||
|
||
## Practice | ||
|
||
Now you can try to create you own shadow files, try to customize some vital text decorations tokens, or even create a new typography token. |
5 changes: 5 additions & 0 deletions
5
packages/vital-examples/src/customizing-design-tokens/base/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// We must export the token collection directly from the module in which | ||
// it is defined, not from /tokens. This verison of the token will never | ||
// be shadowed. | ||
export { default as exampleTextDecorationBase } from '../components/TextDecoration/tokens/exampleTextDecoration'; | ||
export { default as exampleTypographyBase } from '../components/Typography/tokens/exampleTypography'; |
8 changes: 8 additions & 0 deletions
8
...src/customizing-design-tokens/components/TextDecoration/__tests__/TextDecoration.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable jest/valid-describe */ | ||
import { Span, TokenCollection } from '@bodiless/fclasses'; | ||
import { DefaultDomains, testTokens } from '@bodiless/vital-elements'; | ||
import { exampleTextDecoration } from '..'; | ||
|
||
// @todo Fix type matching on text decoration token collection. | ||
const tokenCollection = exampleTextDecoration as any as TokenCollection<any, DefaultDomains>; | ||
describe('TextDecoration', testTokens(Span, tokenCollection)); |
43 changes: 43 additions & 0 deletions
43
...ign-tokens/components/TextDecoration/__tests__/__snapshots__/TextDecoration.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`TextDecoration Matches snapshot for Bold 1`] = ` | ||
<span | ||
className="font-black" | ||
/> | ||
`; | ||
|
||
exports[`TextDecoration Matches snapshot for ExtraBold 1`] = ` | ||
<span | ||
className="font-extrabold" | ||
/> | ||
`; | ||
|
||
exports[`TextDecoration Matches snapshot for Medium 1`] = ` | ||
<span | ||
className="font-medium" | ||
/> | ||
`; | ||
|
||
exports[`TextDecoration Matches snapshot for Normal 1`] = ` | ||
<span | ||
className="font-normal" | ||
/> | ||
`; | ||
|
||
exports[`TextDecoration Matches snapshot for Superscript 1`] = ` | ||
<span | ||
className="align-baseline" | ||
/> | ||
`; | ||
|
||
exports[`TextDecoration Matches snapshot for Underline 1`] = ` | ||
<span | ||
className="underline" | ||
/> | ||
`; | ||
|
||
exports[`TextDecoration Matches snapshot for Uppercase 1`] = ` | ||
<span | ||
className="uppercase" | ||
/> | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/vital-examples/src/customizing-design-tokens/components/TextDecoration/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as exampleTextDecoration } from './tokens'; |
8 changes: 8 additions & 0 deletions
8
...s/src/customizing-design-tokens/components/TextDecoration/tokens/exampleTextDecoration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { asTokenGroup, TextDecorationMeta } from '@bodiless/vital-elements'; | ||
import { vitalTextDecorationBase } from '@bodiless/vital-elements/src/base'; | ||
|
||
// Here we use `asTokenGroup` to share the TextDecorationMeta among all tokens exported. | ||
export default asTokenGroup(TextDecorationMeta)({ | ||
...vitalTextDecorationBase, | ||
Bold: 'font-black', | ||
}); |
3 changes: 3 additions & 0 deletions
3
...es/vital-examples/src/customizing-design-tokens/components/TextDecoration/tokens/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import tokens from './exampleTextDecoration'; | ||
|
||
export default tokens; |
6 changes: 6 additions & 0 deletions
6
...xamples/src/customizing-design-tokens/components/Typography/__tests__/Typography.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* eslint-disable jest/valid-describe */ | ||
import { Span } from '@bodiless/fclasses'; | ||
import { testTokens } from '@bodiless/vital-elements'; | ||
import { exampleTypography } from '..'; | ||
|
||
describe('Typography', testTokens(Span, exampleTypography)); |
Oops, something went wrong.