Skip to content

Commit 6590966

Browse files
committed
feat(many): add solution for using both old and new token system in the same app
1 parent 974eefd commit 6590966

File tree

152 files changed

+1276
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1276
-256
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Migrating components to new theming system
3+
category: Contributor Guides
4+
order: 01
5+
---
6+
7+
# Token migration
8+
9+
The new token system consists of auto-generated tokens form design. They can be imported from `ui-themes`.
10+
11+
## Changing tokens only
12+
13+
The migration strategy with the least amount of effort is only changing tokens. This approach keeps the component as class-based and retains the `View` component.
14+
15+
Changes needed:
16+
17+
- Import token types from `@instructure/ui-themes` instead of `@instructure/shared-types`
18+
- Update `generateStyle` function to use `NewComponentTypes['ComponentName']` for the theme parameter
19+
- Replace old theme tokens with new token names from the design system
20+
- Replace `@withStyleRework` decorator with `@withStyle` and remove `generateComponentTheme`
21+
- delete `theme.ts`
22+
23+
If tokens are from a different (usually parent) components, add the `componentID` of that component as second paramater of `@withStyle` and use that name in the `generateStyle` function in `style.ts`: `NewComponentTypes['ParentComponentNameWithTheTokens']`
24+
25+
`generateStyle` accepts a third parameter as well, which are the `sharedTokens`. These provide tokens for shared behaviors such as focus rings, shadows or margins. `'@instructure/emotion'` has various util functions that uses these, such as `calcMarginFromShorthand` and `calcFocusOutlineStyles`.
26+
27+
## Removing View
28+
29+
For some components it makes sense to remove the `View` component underneath the component structure. Most of the time, `View` only provides margins, focus rings, or minor visual aid. These can be replicated - in most cases - by the `sharedTokens` and their utils.
30+
31+
Ideally all occurrences of `View` would be eliminated from the codebase.
32+
33+
## Transforming class based components to functional
34+
35+
The ultimate goal is to migrate all components to functional based ones. Currently it's not a priority and detailed migration guides will be available later. For the time being, `Avatar` or `RadioInput` can be used as starting reference points.

packages/__docs__/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@instructure/ui-color-utils": "workspace:*",
5151
"@instructure/ui-date-input": "workspace:*",
5252
"@instructure/ui-date-time-input": "workspace:*",
53+
"@instructure/ui-decorator": "workspace:*",
5354
"@instructure/ui-dialog": "workspace:*",
5455
"@instructure/ui-dom-utils": "workspace:*",
5556
"@instructure/ui-drawer-layout": "workspace:*",

packages/__docs__/resolve.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const alias = {
5858
import.meta.dirname,
5959
'../ui-date-time-input/src/'
6060
),
61+
'@instructure/ui-decorator$': path.resolve(import.meta.dirname, '../ui-decorator/src/'),
6162
'@instructure/ui-dialog$': path.resolve(import.meta.dirname, '../ui-dialog/src/'),
6263
'@instructure/ui-docs-client$': path.resolve(
6364
import.meta.dirname,

packages/__docs__/src/App/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
} from 'react'
3333

3434
import { Alert } from '@instructure/ui-alerts'
35-
import { InstUISettingsProvider, withStyle, Global } from '@instructure/emotion'
35+
import { InstUISettingsProvider, Global } from '@instructure/emotion'
36+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
3637
import { Flex } from '@instructure/ui-flex'
3738
import { Text } from '@instructure/ui-text'
3839
import { View } from '@instructure/ui-view'

packages/__docs__/src/ColorBand/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Component } from 'react'
2727
import { Flex } from '@instructure/ui-flex'
2828
import { View } from '@instructure/ui-view'
2929

30-
import { withStyle } from '@instructure/emotion'
30+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
3131
import generateStyle from './styles'
3232
import generateComponentTheme from './theme'
3333
import { allowedProps } from './props'

packages/__docs__/src/ColorSwatch/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import { Component } from 'react'
2626

2727
import { isValid } from '@instructure/ui-color-utils'
28-
import { withStyle } from '@instructure/emotion'
28+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
2929

3030
import generateStyle from './styles'
3131
import generateComponentTheme from './theme'

packages/__docs__/src/ComponentTheme/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import { Component } from 'react'
2626

27-
import { withStyle } from '@instructure/emotion'
27+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
2828
import { Table } from '@instructure/ui-table'
2929
import { View } from '@instructure/ui-view'
3030

packages/__docs__/src/Document/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { View } from '@instructure/ui-view'
2929
import { Tabs } from '@instructure/ui-tabs'
3030
import type { TabsProps } from '@instructure/ui-tabs'
3131
import { SourceCodeEditor } from '@instructure/ui-source-code-editor'
32-
import { withStyle } from '@instructure/emotion'
32+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
3333

3434
import generateStyle from './styles'
3535

packages/__docs__/src/Figure/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { List } from '@instructure/ui-list'
3434
import { Responsive } from '@instructure/ui-responsive'
3535
import { View } from '@instructure/ui-view'
3636

37-
import { withStyle } from '@instructure/emotion'
37+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
3838

3939
import generateStyle from './styles'
4040
import generateComponentTheme from './theme'

packages/__docs__/src/Hero/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { IconGithubSolid, IconCheckMarkSolid } from '@instructure/ui-icons'
3535
import { AccessibleContent } from '@instructure/ui-a11y-content'
3636
import { InlineSVG, SVGIcon } from '@instructure/ui-svg-images'
3737

38-
import { withStyle } from '@instructure/emotion'
38+
import { withStyleForDocs as withStyle } from '../withStyleForDocs'
3939

4040
import generateStyle from './styles'
4141
import generateComponentTheme from './theme'

0 commit comments

Comments
 (0)