diff --git a/a.out b/a.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/guides/upgrade-guide.md b/docs/guides/upgrade-guide.md index 138aa4e0a3..4e542bd60b 100644 --- a/docs/guides/upgrade-guide.md +++ b/docs/guides/upgrade-guide.md @@ -27,7 +27,6 @@ The following variant values have been **deprecated** and will be removed in a f - `'inline-small'` - `'standalone-small'` - ### Theme variable changes - theme variable `fontSize` is now removed @@ -211,6 +210,27 @@ type: example - theme variable `requiredInvalidColor` is now removed - `error` or `success` messages are no longer displayed when the component is '`readOnly` or `disabled` +### Tabs.Panel + +- theme variable `color` is now renamed to `textColor` +- theme variable `focusOutlineColor` is now removed and the style uses the `sharedTokens.focusOutline.infoColor` + +### Tabs.Tab + +- theme variable `defaultColor` is now renamed to `defaultTextColor` +- theme variable `defaultHoverBorderColor` is now removed as it was unused + +### Tray + +- theme variable `background` is now renamed to `backgroundColor` +- theme variable `xSmallWidth` is now renamed to `widthXs` +- theme variable `smallWidth` is now renamed to `widthSm` +- theme variable `regularWidth` is now renamed to `widthMg` +- theme variable `mediumWidth` is now renamed to `widthLg` +- theme variable `largeWidth` is now renamed to `widthXl` +- theme variable `borderStyle` is now removed +- theme variable `position` is now removed + ## Codemods To ease the upgrade, we provide codemods that will automate most of the changes. Pay close attention to its output, it cannot refactor complex code! The codemod scripts can be run via the following commands: diff --git a/packages/emotion/src/withStyle.tsx b/packages/emotion/src/withStyle.tsx index 2e6225c3e6..1f126ab661 100644 --- a/packages/emotion/src/withStyle.tsx +++ b/packages/emotion/src/withStyle.tsx @@ -152,6 +152,8 @@ const withStyle = decorator( ) => { const displayName = ComposedComponent.displayName || ComposedComponent.name + const componentId = ComposedComponent.componentId?.replace('.', '') + const WithStyle: ForwardRefExoticComponent< PropsWithoutRef & RefAttributes > & { @@ -182,7 +184,7 @@ const withStyle = decorator( ...defaultValues } - const componentWithTokensId = useTokensFrom ?? displayName + const componentWithTokensId = useTokensFrom ?? componentId const baseComponentTheme = theme.newTheme.components[ diff --git a/packages/ui-scripts/lib/build/buildThemes/generateComponents.js b/packages/ui-scripts/lib/build/buildThemes/generateComponents.js index 195f39db57..185704108f 100644 --- a/packages/ui-scripts/lib/build/buildThemes/generateComponents.js +++ b/packages/ui-scripts/lib/build/buildThemes/generateComponents.js @@ -52,12 +52,12 @@ export const resolveReferences = (semantics, key) => { if (typeof value[key] === 'object') { return ( acc + - `"${key}": {${resolveReferences(value, key)}}${ + `${key}: {${resolveReferences(value, key)}}${ index + 1 === Object.keys(value).length ? '' : ',\n' }` ) } - return acc + `"${key}": ${resolveReferences(value, key)}` + return acc + `${key}: ${resolveReferences(value, key)}` }, '') } if (isReference(value)) { diff --git a/packages/ui-scripts/lib/build/buildThemes/setupThemes.js b/packages/ui-scripts/lib/build/buildThemes/setupThemes.js index bc30c7179d..0ca8c6afba 100644 --- a/packages/ui-scripts/lib/build/buildThemes/setupThemes.js +++ b/packages/ui-scripts/lib/build/buildThemes/setupThemes.js @@ -95,7 +95,7 @@ const setupThemes = async (targetPath, input) => { input, themeData[theme].semantic ) - // console.log(JSON.stringify(mergedSemanticData)); + const semantics = generateSemantics(mergedSemanticData) const semanticsTypes = generateSemanticsType(mergedSemanticData) const semanticsFileContent = ` @@ -109,19 +109,44 @@ const setupThemes = async (targetPath, input) => { ` await createFile(`${themePath}/semantics.ts`, semanticsFileContent) + const componentAndSubcomponentNames = [] //components for (const componentpath of themeData[theme].components) { const rawComponentName = componentpath.split('/')[componentpath.split('/').length - 1] - const componentName = + const mainComponentName = rawComponentName[0].toLowerCase() + rawComponentName.slice(1) - const component = generateComponent(input[componentpath][componentName]) - const componentTypes = generateComponentType( - input[componentpath][componentName] + //figma needs prefixed subcomponents, e.g.: for modal => modalHeader, modalBody, etc... and we need only the name of the subcomponent, so we access the data with the subcomponent object, containing the prefixed version and making a non-prefixed list of the same components to produce files, variable, theme names + const subcomponents = Object.keys(input[componentpath]) + const subcomponentNames = subcomponents.reduce( + (acc, subcomponent) => [ + ...acc, + ...(subcomponent.startsWith(acc[0]) && + subcomponent.length > acc[0].length + ? [unCapitalize(subcomponent.slice(acc[0].length))] + : []) + ], + [subcomponents[0]] ) - const componentFileContent = ` + subcomponents.forEach(async (subcomponent, subcomponentIndex) => { + const subcomponentName = subcomponentNames[subcomponentIndex] + + const componentName = + subcomponent === mainComponentName + ? mainComponentName + : `${mainComponentName}${capitalize(subcomponentName)}` + + componentAndSubcomponentNames.push(componentName) + + const component = generateComponent(input[componentpath][subcomponent]) + + const componentTypes = generateComponentType( + input[componentpath][subcomponent] + ) + + const componentFileContent = ` import semantics from "../semantics" import type { ${capitalize( componentName @@ -131,28 +156,28 @@ const setupThemes = async (targetPath, input) => { export default ${componentName} ` - await createFile( - `${themePath}/components/${componentName}.ts`, - componentFileContent - ) - if (themeIndex === 0) { - let importSemantics = '' - if (componentTypes.includes(`Semantics[`)) { - importSemantics = `import type { Semantics } from "../${theme}/semantics"` - } - let importBoxShadow = '' - if (componentTypes.includes('TokenBoxshadowValueInst')) { - importBoxShadow = `import type { TokenBoxshadowValueInst } from '../commonTypes'` - } - let importBorder = '' - if (componentTypes.includes('TokenBorderValue')) { - importBorder = `import type { TokenBorderValue } from '@tokens-studio/types'` - } - let importTypography = '' - if (componentTypes.includes('TokenTypographyValueInst')) { - importTypography = `import type { TokenTypographyValueInst } from '../commonTypes'` - } - const typeFileContent = ` + await createFile( + `${themePath}/components/${componentName}.ts`, + componentFileContent + ) + if (themeIndex === 0) { + let importSemantics = '' + if (componentTypes.includes(`Semantics[`)) { + importSemantics = `import type { Semantics } from "../${theme}/semantics"` + } + let importBoxShadow = '' + if (componentTypes.includes('TokenBoxshadowValueInst')) { + importBoxShadow = `import type { TokenBoxshadowValueInst } from '../commonTypes'` + } + let importBorder = '' + if (componentTypes.includes('TokenBorderValue')) { + importBorder = `import type { TokenBorderValue } from '@tokens-studio/types'` + } + let importTypography = '' + if (componentTypes.includes('TokenTypographyValueInst')) { + importTypography = `import type { TokenTypographyValueInst } from '../commonTypes'` + } + const typeFileContent = ` ${importSemantics} ${importBoxShadow} ${importBorder} @@ -162,30 +187,28 @@ const setupThemes = async (targetPath, input) => { export default ${capitalize(componentName)} ` - await createFile( - `${targetPath}/componentTypes/${componentName}.ts`, - typeFileContent - ) - } + await createFile( + `${targetPath}/componentTypes/${componentName}.ts`, + typeFileContent + ) + } + }) } //index file - const componentImports = themeData[theme].components - .map((componentpath) => { - const componentName = - componentpath.split('/')[componentpath.split('/').length - 1] - - return `import ${unCapitalize( - componentName - )} from "./components/${unCapitalize(componentName)}"` - }) + const componentImports = componentAndSubcomponentNames + .map( + (componentName) => + `import ${unCapitalize( + componentName + )} from "./components/${unCapitalize(componentName)}"` + ) .join('\n') - const componentNames = themeData[theme].components - .map((componentpath) => { - const componentName = - componentpath.split('/')[componentpath.split('/').length - 1] - return `${componentName}: ${unCapitalize(componentName)}` - }) + const componentNames = componentAndSubcomponentNames + .map( + (componentName) => + `${capitalize(componentName)}: ${unCapitalize(componentName)}` + ) .join(',\n') const indexFileContent = ` import primitives, {type Primitives} from "./primitives"; @@ -209,23 +232,19 @@ const setupThemes = async (targetPath, input) => { //index type file if (themeIndex === 0) { - const componentTypeImports = themeData[theme].components - .map((componentpath) => { - const componentName = - componentpath.split('/')[componentpath.split('/').length - 1] - - return `import type ${capitalize( - componentName - )} from './${unCapitalize(componentName)}'` - }) + const componentTypeImports = componentAndSubcomponentNames + .map( + (componentName) => + `import type ${capitalize(componentName)} from './${unCapitalize( + componentName + )}'` + ) .join('\n') - const componentTypeExport = themeData[theme].components - .map((componentpath) => { - const componentName = - componentpath.split('/')[componentpath.split('/').length - 1] - - return `${capitalize(componentName)}:${capitalize(componentName)}` - }) + const componentTypeExport = componentAndSubcomponentNames + .map( + (componentName) => + `${capitalize(componentName)}:${capitalize(componentName)}` + ) .join(',\n') const componentsTypesFileContent = ` @@ -270,7 +289,7 @@ const setupThemes = async (targetPath, input) => { textDecoration?: TokenTextDecorationValue } -export type BaseTheme

= Record, S extends Record = Record> = { + export type BaseTheme

= Record, S extends Record = Record> = { primitives: P semantics: S components: ComponentTypes diff --git a/packages/ui-tabs/src/Tabs/Panel/index.tsx b/packages/ui-tabs/src/Tabs/Panel/index.tsx index b645911098..47d0cfbfcb 100644 --- a/packages/ui-tabs/src/Tabs/Panel/index.tsx +++ b/packages/ui-tabs/src/Tabs/Panel/index.tsx @@ -28,10 +28,9 @@ import { View } from '@instructure/ui-view' import { passthroughProps } from '@instructure/ui-react-utils' import { Transition } from '@instructure/ui-motion' -import { withStyleRework as withStyle } from '@instructure/emotion' +import { withStyle } from '@instructure/emotion' import generateStyle from './styles' -import generateComponentTheme from './theme' import type { TabsPanelProps } from './props' import { allowedProps } from './props' @@ -41,7 +40,7 @@ parent: Tabs id: Tabs.Panel --- **/ -@withStyle(generateStyle, generateComponentTheme) +@withStyle(generateStyle) class Panel extends Component { static readonly componentId = 'Tabs.Panel' diff --git a/packages/ui-tabs/src/Tabs/Panel/styles.ts b/packages/ui-tabs/src/Tabs/Panel/styles.ts index 87774eee3f..2c09f7a6b3 100644 --- a/packages/ui-tabs/src/Tabs/Panel/styles.ts +++ b/packages/ui-tabs/src/Tabs/Panel/styles.ts @@ -22,8 +22,14 @@ * SOFTWARE. */ -import type { TabsPanelTheme } from '@instructure/shared-types' import type { TabsPanelProps, TabsPanelStyle } from './props' +import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes' + +type StyleParams = { + maxHeight: TabsPanelProps['maxHeight'] + isSelected: TabsPanelProps['isSelected'] + isHidden: boolean +} /** * --- @@ -31,17 +37,15 @@ import type { TabsPanelProps, TabsPanelStyle } from './props' * --- * Generates the style object from the theme and provided additional information * @param {Object} componentTheme The theme variable object. - * @param {Object} props the props of the component, the style is applied to - * @param {Object} state the state of the component, the style is applied to + * @param {Object} params the props and passed through data of the component, the style is applied to * @return {Object} The final style object, which will be used in the component */ const generateStyle = ( - componentTheme: TabsPanelTheme, - props: TabsPanelProps, - state: { isHidden: boolean } + componentTheme: NewComponentTypes['TabsPanel'], + params: StyleParams, + sharedTokens: SharedTokens ): TabsPanelStyle => { - const { maxHeight, isSelected } = props - const { isHidden } = state + const { maxHeight, isSelected, isHidden } = params return { panel: { @@ -61,7 +65,7 @@ const generateStyle = ( display: 'none' }), '&:focus': { - outlineColor: componentTheme.focusOutlineColor + outlineColor: sharedTokens.focusOutline.infoColor } }, content: { @@ -70,10 +74,10 @@ const generateStyle = ( width: '100%', height: '100%', borderWidth: componentTheme.borderWidth, - borderStyle: componentTheme.borderStyle, + borderStyle: 'solid', background: componentTheme.background, borderColor: componentTheme.borderColor, - color: componentTheme.color, + color: componentTheme.textColor, borderLeft: 'none', borderRight: 'none', borderBottom: 'none', diff --git a/packages/ui-tabs/src/Tabs/Panel/theme.ts b/packages/ui-tabs/src/Tabs/Panel/theme.ts deleted file mode 100644 index 85b2800b57..0000000000 --- a/packages/ui-tabs/src/Tabs/Panel/theme.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 - present Instructure, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import type { Theme, ThemeSpecificStyle } from '@instructure/ui-themes' -import { TabsPanelTheme } from '@instructure/shared-types' - -/** - * Generates the theme object for the component from the theme and provided additional information - * @param {Object} theme The actual theme object. - * @return {Object} The final theme object with the overrides and component variables - */ -const generateComponentTheme = (theme: Theme): TabsPanelTheme => { - const { typography, colors, borders, key: themeName } = theme - - const themeSpecificStyle: ThemeSpecificStyle = { - canvas: { - color: theme['ic-brand-font-color-dark'], - focusOutlineColor: theme['ic-brand-primary'] - } - } - - const componentVariables: TabsPanelTheme = { - fontSize: typography?.fontSizeMedium, - fontFamily: typography?.fontFamily, - fontWeight: typography?.fontWeightNormal, - lineHeight: typography?.lineHeight, - color: colors?.contrasts?.grey125125, - background: colors?.contrasts?.white1010, - borderColor: colors?.contrasts?.grey3045, - borderWidth: borders?.widthSmall, - borderStyle: borders?.style, - defaultOverflowY: 'auto', - focusOutlineColor: colors.contrasts.blue4570 - } - - return { - ...componentVariables, - ...themeSpecificStyle[themeName] - } -} - -export default generateComponentTheme diff --git a/packages/ui-tabs/src/Tabs/Tab/index.tsx b/packages/ui-tabs/src/Tabs/Tab/index.tsx index c6fe82bc5f..03b86363fb 100644 --- a/packages/ui-tabs/src/Tabs/Tab/index.tsx +++ b/packages/ui-tabs/src/Tabs/Tab/index.tsx @@ -28,10 +28,9 @@ import { passthroughProps, callRenderProp } from '@instructure/ui-react-utils' import { View } from '@instructure/ui-view' import type { ViewOwnProps } from '@instructure/ui-view' -import { withStyleRework as withStyle } from '@instructure/emotion' +import { withStyle } from '@instructure/emotion' import generateStyle from './styles' -import generateComponentTheme from './theme' import type { TabsTabProps } from './props' import { allowedProps } from './props' @@ -42,7 +41,7 @@ parent: Tabs id: Tabs.Tab --- **/ -@withStyle(generateStyle, generateComponentTheme) +@withStyle(generateStyle) class Tab extends Component { static readonly componentId = 'Tabs.Tab' diff --git a/packages/ui-tabs/src/Tabs/Tab/styles.ts b/packages/ui-tabs/src/Tabs/Tab/styles.ts index 22c547453f..2662574982 100644 --- a/packages/ui-tabs/src/Tabs/Tab/styles.ts +++ b/packages/ui-tabs/src/Tabs/Tab/styles.ts @@ -24,9 +24,16 @@ import { keyframes } from '@instructure/emotion' -import type { TabsTabTheme } from '@instructure/shared-types' +import type { NewComponentTypes } from '@instructure/ui-themes' import type { TabsTabProps, TabsTabStyle } from './props' +type StyleParams = { + variant: TabsTabProps['variant'] + isSelected: TabsTabProps['isSelected'] + isDisabled: TabsTabProps['isDisabled'] + isOverflowScroll: TabsTabProps['isOverflowScroll'] +} + // keyframes have to be outside of 'generateStyle', // since it is causing problems in style recalculation const selectedTab = keyframes` @@ -41,15 +48,14 @@ const selectedTab = keyframes` * --- * Generates the style object from the theme and provided additional information * @param {Object} componentTheme The theme variable object. - * @param {Object} props the props of the component, the style is applied to - * @param {Object} state the state of the component, the style is applied to + * @param {Object} params the props and passed through data of the component, the style is applied to * @return {Object} The final style object, which will be used in the component */ const generateStyle = ( - componentTheme: TabsTabTheme, - props: TabsTabProps + componentTheme: NewComponentTypes['TabsTab'], + params: StyleParams ): TabsTabStyle => { - const { variant, isSelected, isDisabled, isOverflowScroll } = props + const { variant, isSelected, isDisabled, isOverflowScroll } = params const variants = { default: { @@ -57,7 +63,7 @@ const generateStyle = ( lineHeight: 1, position: 'relative', zIndex: componentTheme.zIndex, - color: componentTheme.defaultColor, + color: componentTheme.defaultTextColor, ...(isDisabled && { fontWeight: 'normal' }), @@ -88,7 +94,7 @@ const generateStyle = ( }, secondary: { padding: '0.75rem 1rem', // if horizontal padding changes, update `scrollOverlayWidthSecondary` in `Tabs/theme.js` - color: componentTheme.secondaryColor, + color: componentTheme.secondaryTextColor, marginInlineEnd: '0.2em', marginBottom: isOverflowScroll ? '0rem' : '-0.0625rem', border: '0.0625rem solid transparent', diff --git a/packages/ui-tabs/src/Tabs/Tab/theme.ts b/packages/ui-tabs/src/Tabs/Tab/theme.ts deleted file mode 100644 index 8deaba48a4..0000000000 --- a/packages/ui-tabs/src/Tabs/Tab/theme.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 - present Instructure, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import type { Theme, ThemeSpecificStyle } from '@instructure/ui-themes' -import { TabsTabTheme } from '@instructure/shared-types' - -/** - * Generates the theme object for the component from the theme and provided additional information - * @param {Object} theme The actual theme object. - * @return {Object} The final theme object with the overrides and component variables - */ -const generateComponentTheme = (theme: Theme): TabsTabTheme => { - const { colors, typography, stacking, key: themeName } = theme - - const themeSpecificStyle: ThemeSpecificStyle = { - canvas: { - defaultColor: theme['ic-brand-font-color-dark'], - defaultSelectedBorderColor: theme['ic-brand-primary'], - - secondaryColor: theme['ic-brand-font-color-dark'] - } - } - - const componentVariables: TabsTabTheme = { - fontFamily: typography?.fontFamily, - fontWeight: typography?.fontWeightNormal, - lineHeight: typography?.lineHeightCondensed, - fontSize: typography?.fontSizeMedium, - - defaultColor: colors?.contrasts?.grey125125, - defaultHoverBorderColor: colors?.contrasts?.grey1214, - defaultSelectedBorderColor: colors?.contrasts?.blue4570, - - secondaryColor: colors?.contrasts?.grey125125, - secondarySelectedBackground: colors?.contrasts?.white1010, - secondarySelectedBorderColor: colors?.contrasts?.grey3045, - - zIndex: stacking?.above - } - - return { - ...componentVariables, - ...themeSpecificStyle[themeName] - } -} - -export default generateComponentTheme diff --git a/packages/ui-tabs/src/Tabs/index.tsx b/packages/ui-tabs/src/Tabs/index.tsx index 19815b8fa4..e155d3608c 100644 --- a/packages/ui-tabs/src/Tabs/index.tsx +++ b/packages/ui-tabs/src/Tabs/index.tsx @@ -48,10 +48,9 @@ import { debounce } from '@instructure/debounce' import type { Debounced } from '@instructure/debounce' import { px } from '@instructure/ui-utils' -import { withStyleRework as withStyle } from '@instructure/emotion' +import { withStyle } from '@instructure/emotion' import generateStyle from './styles' -import generateComponentTheme from './theme' import { Tab } from './Tab' import { Panel } from './Panel' @@ -70,7 +69,7 @@ type PanelChild = ComponentElement category: components --- **/ -@withStyle(generateStyle, generateComponentTheme) +@withStyle(generateStyle) class Tabs extends Component { static readonly componentId = 'Tabs' diff --git a/packages/ui-tabs/src/Tabs/styles.ts b/packages/ui-tabs/src/Tabs/styles.ts index 354d416b84..746f7c3434 100644 --- a/packages/ui-tabs/src/Tabs/styles.ts +++ b/packages/ui-tabs/src/Tabs/styles.ts @@ -22,24 +22,28 @@ * SOFTWARE. */ -import type { TabsTheme } from '@instructure/shared-types' import type { TabsProps, TabsStyle } from './props' +import type { NewComponentTypes } from '@instructure/ui-themes' +type StyleParams = { + tabOverflow: TabsProps['tabOverflow'] + fixHeight: TabsProps['fixHeight'] + variant: TabsProps['variant'] +} /** * --- * private: true * --- * Generates the style object from the theme and provided additional information * @param {Object} componentTheme The theme variable object. - * @param {Object} props the props of the component, the style is applied to - * @param {Object} state the state of the component, the style is applied to + * @param {Object} params the props and passed through data of the component, the style is applied to * @return {Object} The final style object, which will be used in the component */ const generateStyle = ( - componentTheme: TabsTheme, - props: TabsProps + componentTheme: NewComponentTypes['Tabs'], + params: StyleParams ): TabsStyle => { - const { variant, tabOverflow, fixHeight } = props + const { variant, tabOverflow, fixHeight } = params // fixHeight can be 0, so simply `fixheight` could return falsy value const hasFixedHeight = typeof fixHeight !== 'undefined' @@ -51,7 +55,7 @@ const generateStyle = ( scrollOverlay: { width: componentTheme.scrollOverlayWidthDefault } }, secondary: { - container: {}, + container: { background: componentTheme.defaultBackground }, tabs: {}, scrollOverlay: { width: componentTheme.scrollOverlayWidthSecondary } } diff --git a/packages/ui-tabs/src/Tabs/theme.ts b/packages/ui-tabs/src/Tabs/theme.ts deleted file mode 100644 index c87ec715a3..0000000000 --- a/packages/ui-tabs/src/Tabs/theme.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 - present Instructure, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import type { Theme } from '@instructure/ui-themes' -import { TabsTheme } from '@instructure/shared-types' - -/** - * Generates the theme object for the component from the theme and provided additional information - * @param {Object} theme The actual theme object. - * @return {Object} The final theme object with the overrides and component variables - */ -const generateComponentTheme = (theme: Theme): TabsTheme => { - const { borders, colors, stacking } = theme - - const componentVariables: TabsTheme = { - defaultBackground: colors?.contrasts?.white1010, - scrollFadeColor: colors?.contrasts?.white1010, - tabVerticalOffset: borders?.widthSmall, // gives effect of selected tab "bar" overlaying bottom border - zIndex: stacking?.above, - scrollOverlayWidthDefault: '5rem', // has to be 4 times the horizontal padding of the default style tab - scrollOverlayWidthSecondary: '3rem' // has to be 3 times the horizontal padding of the secondary style tab - } - - return { - ...componentVariables - } -} - -export default generateComponentTheme diff --git a/packages/ui-top-nav-bar/src/TopNavBar/TopNavBarBreadcrumb/index.tsx b/packages/ui-top-nav-bar/src/TopNavBar/TopNavBarBreadcrumb/index.tsx index 65fd4821b9..a038b90efa 100644 --- a/packages/ui-top-nav-bar/src/TopNavBar/TopNavBarBreadcrumb/index.tsx +++ b/packages/ui-top-nav-bar/src/TopNavBar/TopNavBarBreadcrumb/index.tsx @@ -51,6 +51,7 @@ class TopNavBarBreadcrumb extends Component< TopNavBarBreadcrumbProps, TopNavBarBreadcrumbState > { + static readonly componentId = 'TopNavBar.Breadcrumb' static allowedProps = allowedProps static defaultProps = {} diff --git a/packages/ui-tray/src/Tray/index.tsx b/packages/ui-tray/src/Tray/index.tsx index 35723157df..ae48164fbf 100644 --- a/packages/ui-tray/src/Tray/index.tsx +++ b/packages/ui-tray/src/Tray/index.tsx @@ -33,9 +33,8 @@ import type { PortalNode } from '@instructure/ui-portal' import { mirrorHorizontalPlacement } from '@instructure/ui-position' import { Transition } from '@instructure/ui-motion' import type { TransitionType } from '@instructure/ui-motion' -import { withStyleRework as withStyle } from '@instructure/emotion' +import { withStyle } from '@instructure/emotion' import generateStyle from './styles' -import generateComponentTheme from './theme' import { allowedProps } from './props' import type { TrayProps, TrayState } from './props' import { Mask } from '@instructure/ui-overlays' @@ -45,7 +44,7 @@ import { Mask } from '@instructure/ui-overlays' category: components --- **/ -@withStyle(generateStyle, generateComponentTheme) +@withStyle(generateStyle) @textDirectionContextConsumer() class Tray extends Component { static readonly componentId = 'Tray' diff --git a/packages/ui-tray/src/Tray/styles.ts b/packages/ui-tray/src/Tray/styles.ts index 27d9e6c4fc..f043af163e 100644 --- a/packages/ui-tray/src/Tray/styles.ts +++ b/packages/ui-tray/src/Tray/styles.ts @@ -21,30 +21,34 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - -import type { TrayTheme } from '@instructure/shared-types' +import type { NewComponentTypes } from '@instructure/ui-themes' import type { TrayProps, TrayStyle } from './props' +type StyleParams = { + border: TrayProps['border'] + shadow: TrayProps['shadow'] + size: TrayProps['size'] + placement: TrayProps['placement'] +} /** * --- * private: true * --- * Generates the style object from the theme and provided additional information * @param {Object} componentTheme The theme variable object. - * @param {Object} props the props of the component, the style is applied to - * @param {Object} state the state of the component, the style is applied to + * @param {Object} params the props and passed through data of the component, the style is applied to * @return {Object} The final style object, which will be used in the component */ const generateStyle = ( - componentTheme: TrayTheme, - props: TrayProps + componentTheme: NewComponentTypes['Tray'], + params: StyleParams ): TrayStyle => { - const { border, shadow, size, placement } = props + const { border, shadow, size, placement } = params const borderStyle = { borderWidth: 0, borderColor: componentTheme.borderColor, - borderStyle: componentTheme.borderStyle + borderStyle: 'solid' } const shadowStyle = shadow @@ -111,11 +115,11 @@ const generateStyle = ( : {} const sizeVariants = { - 'x-small': componentTheme.xSmallWidth, - small: componentTheme.smallWidth, - regular: componentTheme.regularWidth, - medium: componentTheme.mediumWidth, - large: componentTheme.largeWidth + 'x-small': componentTheme.widthXs, + small: componentTheme.widthSm, + regular: componentTheme.widthMd, + medium: componentTheme.widthLg, + large: componentTheme.widthXl } const sizeStyle = @@ -128,8 +132,9 @@ const generateStyle = ( return { tray: { label: 'tray', - backgroundColor: componentTheme.background, - position: componentTheme.position, + padding: componentTheme.padding, + backgroundColor: componentTheme.backgroundColor, + position: 'fixed', overflowY: 'auto', overflowX: 'hidden', boxSizing: 'border-box', diff --git a/packages/ui-tray/src/Tray/theme.ts b/packages/ui-tray/src/Tray/theme.ts deleted file mode 100644 index 045ee63f7e..0000000000 --- a/packages/ui-tray/src/Tray/theme.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 - present Instructure, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import type { Theme } from '@instructure/ui-themes' -import { TrayTheme } from '@instructure/shared-types' - -/** - * Generates the theme object for the component from the theme and provided additional information - * @param {Object} theme The actual theme object. - * @return {Object} The final theme object with the overrides and component variables - */ -const generateComponentTheme = (theme: Theme): TrayTheme => { - const { colors, borders, shadows, breakpoints, stacking } = theme - - const componentVariables: TrayTheme = { - background: colors?.contrasts?.white1010, - borderColor: colors?.contrasts?.grey1424, - borderWidth: borders?.widthSmall, - borderStyle: borders?.style, - boxShadow: shadows?.depth3, - xSmallWidth: breakpoints?.xSmall, - smallWidth: '20em', // 368px - regularWidth: breakpoints?.small, - mediumWidth: breakpoints?.medium, - largeWidth: breakpoints?.large, - zIndex: stacking?.topmost, - position: 'fixed' - } - - return { - ...componentVariables - } -} - -export default generateComponentTheme