Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions docs/guides/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,80 @@ type: embed
]}
/>

```
### Modal

#### Modal

```js
---
type: embed
---
<V12ChangelogTable
added={[
{name:"borderWidth",note:""},
{name:"inverseBorderColor",note:""},
]}
changed={[
{oldName:"background",newName:"backgroundColor",note:""},
{oldName:"inverseBackground",newName:"inverseBackgroundColor",note:""},
]}
/>

```

#### Modal Body

```js
---
type: embed
---
<V12ChangelogTable
added={[
{name:"padding",note:""},
{name:"paddingCompact",note:""},
]}
changed={[
{oldName:"inverseBackground",newName:"inverseBackgroundColor",note:""},
]}
/>

```

#### Modal Footer

```js
---
type: embed
---
<V12ChangelogTable
added={[
{name:"paddingCompact",note:""},
]}
changed={[
{oldName:"background",newName:"backgroundColor",note:""},
{oldName:"inverseBackground",newName:"inverseBackgroundColor",note:""},
]}
/>

```

#### Modal Header

```js
---
type: embed
---
<V12ChangelogTable
added={[
{name:"borderWith",note:""},
]}
changed={[
{oldName:"background",newName:"backgroundColor",note:""},
{oldName:"inverseBackground",newName:"inverseBackgroundColor",note:""},
]}
/>

```

### NumberInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { View } from '@instructure/ui-view'
import type { ViewOwnProps } from '@instructure/ui-view'

import { ModalBody } from '../index'
import generateComponentTheme from '../theme'

const BODY_TEXT = 'Modal-body-text'

Expand All @@ -45,7 +44,7 @@ describe('<ModalBody />', () => {
})

it('should set inverse styles', async () => {
const themeVariables = generateComponentTheme(canvas)
const themeVariables = canvas.newTheme.components.ModalBody
const { findByText } = render(
<ModalBody variant="inverse">{BODY_TEXT}</ModalBody>
)
Expand All @@ -56,7 +55,7 @@ describe('<ModalBody />', () => {
)

expect(modalBody).toBeInTheDocument()
expect(bodyBackground).toBe(themeVariables.inverseBackground)
expect(bodyBackground).toBe(themeVariables.inverseBackgroundColor)
})

it('should set the same width and height as the parent when overflow is set to fit', async () => {
Expand Down
19 changes: 13 additions & 6 deletions packages/ui-modal/src/Modal/ModalBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import { View } from '@instructure/ui-view'
import { omitProps } from '@instructure/ui-react-utils'
import { getCSSStyleDeclaration } from '@instructure/ui-dom-utils'

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 { ModalBodyProps } from './props'
Expand All @@ -42,7 +41,7 @@ parent: Modal
id: Modal.Body
---
**/
@withStyle(generateStyle, generateComponentTheme)
@withStyle(generateStyle, 'ModalBody')
class ModalBody extends Component<ModalBodyProps> {
static readonly componentId = 'Modal.Body'

Expand Down Expand Up @@ -105,8 +104,16 @@ class ModalBody extends Component<ModalBodyProps> {
}

render() {
const { as, elementRef, overflow, variant, padding, children, ...rest } =
this.props
const {
as,
elementRef,
overflow,
variant,
padding,
spacing,
children,
...rest
} = this.props

const passthroughProps = View.omitViewProps(
omitProps(rest, ModalBody.allowedProps),
Expand All @@ -128,7 +135,7 @@ class ModalBody extends Component<ModalBodyProps> {
elementRef={this.handleRef}
as={as}
css={this.props.styles?.modalBody}
padding={padding}
padding={spacing ? undefined : padding}
// check if there is a scrollbar, if so, the element has to be tabbable to be able to scroll with keyboard only
// epsilon tolerance is used to avoid scrollbar for rounding errors
{...(finalRef &&
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-modal/src/Modal/ModalBody/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ModalBodyOwnProps = {
as?: AsElementType
variant?: 'default' | 'inverse'
overflow?: 'scroll' | 'fit'
spacing?: 'default' | 'compact'
}

type PropKeys = keyof ModalBodyOwnProps
Expand All @@ -63,7 +64,8 @@ const allowedProps: AllowedPropKeys = [
'elementRef',
'as',
'variant',
'overflow'
'overflow',
'spacing'
]

export type { ModalBodyProps, ModalBodyState, ModalBodyStyle }
Expand Down
15 changes: 11 additions & 4 deletions packages/ui-modal/src/Modal/ModalBody/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

import type { ModalBodyTheme } from '@instructure/shared-types'
import type { NewComponentTypes } from '@instructure/ui-themes'
import type { ModalBodyProps, ModalBodyStyle } from './props'

/**
Expand All @@ -32,19 +32,25 @@ import type { ModalBodyProps, ModalBodyStyle } 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} sharedTokens Shared theme token object
* @param {Object} state the state of the component, the style is applied to
* @return {Object} The final style object, which will be used in the component
*/
const generateStyle = (
componentTheme: ModalBodyTheme,
componentTheme: NewComponentTypes['ModalBody'],
props: ModalBodyProps
): ModalBodyStyle => {
const { variant } = props
const { variant, spacing } = props

const sizeVariants = {
default: { padding: componentTheme.padding },
compact: { padding: componentTheme.paddingCompact }
}

const backgroundStyle =
variant === 'inverse'
? {
background: componentTheme.inverseBackground
background: componentTheme.inverseBackgroundColor
}
: {}

Expand All @@ -60,6 +66,7 @@ const generateStyle = (
'@media (min-height: 20rem)': {
overflowY: 'auto'
},
...(spacing ? sizeVariants[spacing] : {}),
...backgroundStyle
}
}
Expand Down
41 changes: 0 additions & 41 deletions packages/ui-modal/src/Modal/ModalBody/theme.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import canvas from '@instructure/ui-themes'
import { color2hex } from '@instructure/ui-color-utils'

import { ModalFooter } from '../index'
import generateComponentTheme from '../theme'

const FOOTER_TEXT = 'Modal-footer-text'

Expand All @@ -42,7 +41,7 @@ describe('<ModalFooter />', () => {
})

it('should set inverse styles', async () => {
const themeVariables = generateComponentTheme(canvas)
const themeVariables = canvas.newTheme.components.ModalFooter
const { findByText } = render(
<ModalFooter variant="inverse">{FOOTER_TEXT}</ModalFooter>
)
Expand All @@ -57,7 +56,7 @@ describe('<ModalFooter />', () => {
)

expect(modalFooter).toBeInTheDocument()
expect(footerBackground).toBe(themeVariables.inverseBackground)
expect(footerBackground).toBe(themeVariables.inverseBackgroundColor)
expect(footerBorderColor).toBe(themeVariables.inverseBorderColor)
})
})
5 changes: 2 additions & 3 deletions packages/ui-modal/src/Modal/ModalFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import { Component } from 'react'

import { passthroughProps } from '@instructure/ui-react-utils'
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 { ModalFooterProps } from './props'
Expand All @@ -38,7 +37,7 @@ parent: Modal
id: Modal.Footer
---
**/
@withStyle(generateStyle, generateComponentTheme)
@withStyle(generateStyle, 'ModalFooter')
class ModalFooter extends Component<ModalFooterProps> {
static readonly componentId = 'Modal.Footer'

Expand Down
3 changes: 2 additions & 1 deletion packages/ui-modal/src/Modal/ModalFooter/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
type ModalFooterOwnProps = {
children?: React.ReactNode
variant?: 'default' | 'inverse'
spacing?: 'default' | 'compact'
}

type PropKeys = keyof ModalFooterOwnProps
Expand All @@ -43,7 +44,7 @@ type ModalFooterProps = ModalFooterOwnProps &
OtherHTMLAttributes<ModalFooterOwnProps>

type ModalFooterStyle = ComponentStyle<'modalFooter'>
const allowedProps: AllowedPropKeys = ['children', 'variant']
const allowedProps: AllowedPropKeys = ['children', 'variant', 'spacing']

export type { ModalFooterProps, ModalFooterStyle }
export { allowedProps }
16 changes: 10 additions & 6 deletions packages/ui-modal/src/Modal/ModalFooter/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

import type { ModalFooterTheme } from '@instructure/shared-types'
import type { NewComponentTypes } from '@instructure/ui-themes'
import type { ModalFooterProps, ModalFooterStyle } from './props'

/**
Expand All @@ -32,23 +32,24 @@ import type { ModalFooterProps, ModalFooterStyle } 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} sharedTokens Shared theme token object
* @param {Object} state the state of the component, the style is applied to
* @return {Object} The final style object, which will be used in the component
*/
const generateStyle = (
componentTheme: ModalFooterTheme,
componentTheme: NewComponentTypes['ModalFooter'],
props: ModalFooterProps
): ModalFooterStyle => {
const { variant } = props
const { variant, spacing } = props

const backgroundStyle =
variant === 'inverse'
? {
background: componentTheme.inverseBackground,
background: componentTheme.inverseBackgroundColor,
borderTop: `${componentTheme.borderWidth} solid ${componentTheme.inverseBorderColor}`
}
: {
background: componentTheme.background,
background: componentTheme.backgroundColor,
borderTop: `${componentTheme.borderWidth} solid ${componentTheme.borderColor}`
}

Expand All @@ -57,7 +58,10 @@ const generateStyle = (
label: 'modalFooter',
flex: '0 0 auto',
boxSizing: 'border-box',
padding: componentTheme.padding,
padding:
spacing === 'compact'
? componentTheme.paddingCompact
: componentTheme.padding,
borderBottomRightRadius: componentTheme.borderRadius,
borderBottomLeftRadius: componentTheme.borderRadius,
display: 'flex',
Expand Down
Loading