Skip to content

Commit ca9bbbf

Browse files
committed
feat(many): add new theming solution
1 parent 5480c7f commit ca9bbbf

File tree

43 files changed

+8975
-711
lines changed

Some content is hidden

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

43 files changed

+8975
-711
lines changed

.github/workflows/pr-validation.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,4 @@ jobs:
2020
run: npm run lint:commits
2121
- name: Lint code
2222
run: npm run lint:changes
23-
vitest-tests:
24-
name: Vitest unit tests
25-
runs-on: ubuntu-latest
26-
steps:
27-
- uses: actions/checkout@v4
28-
- uses: actions/setup-node@v4
29-
with:
30-
node-version: '22'
31-
cache: 'npm'
32-
- name: Install dependencies
33-
run: npm ci
34-
- name: Bootstrap project
35-
run: npm run bootstrap
36-
- name: Run vitest unit tests
37-
run: npm run test:vitest
38-
cypress:
39-
name: Cypress component tests
40-
runs-on: ubuntu-latest
41-
steps:
42-
- uses: actions/checkout@v4
43-
- uses: actions/setup-node@v4
44-
with:
45-
node-version: '22'
46-
cache: 'npm'
47-
- name: Install dependencies
48-
run: npm ci
49-
- name: Bootstrap project
50-
run: npm run bootstrap
51-
- name: Run Cypress components tests
52-
run: npm run cy:component
5323

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"packages/*"
1515
],
1616
"scripts": {
17+
"build:themes": "ui-scripts build-themes",
1718
"prestart": "npm run bootstrap",
1819
"start": "npm run start --workspace=docs-app --",
1920
"start:watch": "npm run start:watch --workspace=docs-app --",
@@ -25,7 +26,7 @@
2526
"lint:changes": "npm run lint -- --since HEAD^",
2627
"lint:fix": "lerna run lint:fix --stream",
2728
"lint:commits": "commitlint --from=HEAD^1",
28-
"bootstrap": "node scripts/bootstrap.js",
29+
"bootstrap": "node scripts/bootstrap.js && npm run build:themes",
2930
"build": "lerna run build --stream",
3031
"build:watch": "lerna run build:watch --stream",
3132
"build:docs": "lerna run bundle --stream --scope docs-app",

packages/emotion/src/useStyle.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,18 @@ const useStyle = <P extends (theme: any, params: any) => any>(
5858
} = useStyleParams
5959
const theme = useTheme()
6060

61-
let baseComponentTheme = generateComponentTheme
62-
? generateComponentTheme(theme as BaseTheme)
63-
: {}
61+
let baseComponentTheme =
62+
typeof generateComponentTheme === 'function'
63+
? generateComponentTheme(theme as BaseTheme)
64+
: {}
6465
if (
65-
//@ts-expect-error asd
66+
//@ts-expect-error TODO fix these later
6667
theme.newTheme &&
67-
//@ts-expect-error asd
68+
//@ts-expect-error TODO fix these later
6869
theme.newTheme.components[componentId?.toLocaleLowerCase()]
6970
) {
7071
baseComponentTheme =
71-
//@ts-expect-error asd
72+
//@ts-expect-error TODO fix these later
7273
theme.newTheme.components[componentId?.toLocaleLowerCase()]
7374
}
7475

packages/emotion/src/withStyle.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,34 @@ const withStyle = decorator(
201201
...defaultValues
202202
}
203203

204-
let componentTheme: ComponentTheme =
204+
let baseComponentTheme =
205205
typeof generateComponentTheme === 'function'
206206
? generateComponentTheme(theme as BaseTheme)
207207
: {}
208+
if (
209+
//@ts-expect-error TODO fix these later
210+
theme.newTheme &&
211+
//@ts-expect-error TODO fix these later
212+
theme.newTheme.components[
213+
ComposedComponent.componentId?.toLocaleLowerCase()
214+
]
215+
) {
216+
baseComponentTheme =
217+
//@ts-expect-error TODO fix these later
218+
theme.newTheme.components[
219+
ComposedComponent.componentId?.toLocaleLowerCase()
220+
]
221+
}
208222

209223
const themeOverride = getComponentThemeOverride(
210224
theme,
211225
displayName,
212226
ComposedComponent.componentId,
213227
componentProps,
214-
componentTheme
228+
baseComponentTheme
215229
)
216230

217-
componentTheme = { ...componentTheme, ...themeOverride }
231+
const componentTheme = { ...baseComponentTheme, ...themeOverride }
218232

219233
const [styles, setStyles] = useState(
220234
generateStyle ? generateStyle(componentTheme, componentProps, {}) : {}

packages/ui-color-picker/src/ColorContrast/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ColorContrast extends Component<ColorContrastProps, ColorContrastState> {
119119
{description}
120120
</div>
121121
<div css={styles?.statusIndicatorWrapper}>
122-
<Pill color={pass ? 'success' : 'danger'}>
122+
<Pill color={pass ? 'success' : 'error'}>
123123
{pass ? successLabel : failureLabel}
124124
</Pill>
125125
</div>

packages/ui-pill/src/Pill/README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ type: example
3232
>
3333
Checked In
3434
</Pill>
35-
<Pill
36-
renderIcon={<IconEndLine />}
37-
color="danger"
38-
margin="x-small"
39-
>
40-
Missing
41-
</Pill>
4235
<Pill
4336
renderIcon={<IconClockLine />}
4437
color="warning"
@@ -48,7 +41,7 @@ type: example
4841
</Pill>
4942
<Pill
5043
renderIcon={<IconMessageLine />}
51-
color="alert"
44+
color="error"
5245
margin="x-small"
5346
>
5447
Notification

packages/ui-pill/src/Pill/props.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import type {
3838

3939
type PillOwnProps = {
4040
as?: AsElementType
41-
color?: 'primary' | 'success' | 'danger' | 'info' | 'warning' | 'alert'
41+
color?: 'primary' | 'success' | 'info' | 'warning' | 'error'
4242
/**
4343
* Provides a reference to the underlying HTML element
4444
*/
@@ -76,14 +76,7 @@ type PillStyle = ComponentStyle<
7676
const propTypes: PropValidators<PropKeys> = {
7777
as: PropTypes.elementType,
7878
children: PropTypes.node.isRequired,
79-
color: PropTypes.oneOf([
80-
'primary',
81-
'success',
82-
'danger',
83-
'info',
84-
'warning',
85-
'alert'
86-
]),
79+
color: PropTypes.oneOf(['primary', 'success', 'info', 'warning', 'error']),
8780
elementRef: PropTypes.func,
8881
margin: PropTypes.string,
8982
statusLabel: PropTypes.string,

packages/ui-pill/src/Pill/styles.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import type { PillTheme } from '@instructure/shared-types'
25+
import type { NewCanvas } from '@instructure/ui-themes'
2626
import type { PillProps, PillStyle } from './props'
2727

2828
/**
@@ -36,35 +36,31 @@ import type { PillProps, PillStyle } from './props'
3636
* @return {Object} The final style object, which will be used in the component
3737
*/
3838
const generateStyle = (
39-
componentTheme: PillTheme,
39+
componentTheme: NewCanvas['components']['pill'],
4040
props: PillProps
4141
): PillStyle => {
4242
const { color } = props
4343

4444
const pillColorVariants = {
4545
primary: {
46-
color: componentTheme.primaryColor,
47-
borderColor: componentTheme.primaryColor
46+
color: componentTheme.primaryText,
47+
borderColor: componentTheme.primaryBorder
4848
},
4949
success: {
50-
color: componentTheme.successColor,
51-
borderColor: componentTheme.successColor
52-
},
53-
danger: {
54-
color: componentTheme.dangerColor,
55-
borderColor: componentTheme.dangerColor
50+
color: componentTheme.successText,
51+
borderColor: componentTheme.successBorder
5652
},
5753
info: {
58-
color: componentTheme.infoColor,
59-
borderColor: componentTheme.infoColor
54+
color: componentTheme.infoText,
55+
borderColor: componentTheme.infoBorder
6056
},
6157
warning: {
62-
color: componentTheme.warningColor,
63-
borderColor: componentTheme.warningColor
58+
color: componentTheme.warningText,
59+
borderColor: componentTheme.warningBorder
6460
},
65-
alert: {
66-
color: componentTheme.alertColor,
67-
borderColor: componentTheme.alertColor
61+
error: {
62+
color: componentTheme.errorText,
63+
borderColor: componentTheme.errorBorder
6864
}
6965
}
7066

@@ -74,12 +70,11 @@ const generateStyle = (
7470
display: 'flex',
7571
alignItems: 'center',
7672
justifyContent: 'center',
77-
fontFamily: componentTheme.fontFamily,
7873
boxSizing: 'border-box',
79-
padding: componentTheme.padding,
74+
padding: `0 ${componentTheme.paddingHorizontal}`,
8075
background: componentTheme.background,
8176
borderWidth: componentTheme.borderWidth,
82-
borderStyle: componentTheme.borderStyle,
77+
borderStyle: componentTheme.borderStyle.style,
8378
borderRadius: componentTheme.borderRadius,
8479
/* line-height does not account for top/bottom border width */
8580
lineHeight: `calc(${componentTheme.height} - (${componentTheme.borderWidth} * 2))`,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import path, { dirname } from 'path'
26+
import { fileURLToPath } from 'url'
27+
import fs from 'fs'
28+
import setupThemes from './buildThemes/setupThemes.js'
29+
30+
const __filename = fileURLToPath(import.meta.url)
31+
const __dirname = dirname(__filename)
32+
33+
export default {
34+
command: 'build-themes',
35+
desc: 'Generate themes',
36+
handler: async () => {
37+
const rawData = fs.readFileSync(
38+
path.join(__dirname, 'tokenStudioThemeTokens.json')
39+
)
40+
setupThemes('packages/ui-themes/src/themes/newThemes', rawData)
41+
}
42+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import fs from 'fs'
26+
import { execSync } from 'child_process'
27+
28+
const license = `/*
29+
* The MIT License (MIT)
30+
*
31+
* Copyright (c) 2015 - present Instructure, Inc.
32+
*
33+
* Permission is hereby granted, free of charge, to any person obtaining a copy
34+
* of this software and associated documentation files (the "Software"), to deal
35+
* in the Software without restriction, including without limitation the rights
36+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37+
* copies of the Software, and to permit persons to whom the Software is
38+
* furnished to do so, subject to the following conditions:
39+
*
40+
* The above copyright notice and this permission notice shall be included in all
41+
* copies or substantial portions of the Software.
42+
*
43+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49+
* SOFTWARE.
50+
*/
51+
52+
`
53+
54+
const createFile = (filePath, fileContent) => {
55+
if (fs.existsSync(filePath)) {
56+
fs.unlinkSync(filePath)
57+
}
58+
59+
fs.mkdirSync(filePath.split('/').slice(0, -1).join('/'), { recursive: true })
60+
fs.writeFileSync(filePath, `${license} ${fileContent}`)
61+
// eslint-disable-next-line no-console
62+
console.log(`Creating theme file: ${filePath}`)
63+
execSync(`npx prettier --write ${filePath} --ignore-path .prettierignore`)
64+
}
65+
66+
export default createFile

0 commit comments

Comments
 (0)