Skip to content
Open
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
3 changes: 3 additions & 0 deletions packages/__docs__/buildScripts/DataTypes.mts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type YamlMetaInfo = {
// if true it won't be included in the docs
private: boolean
tags?: string
// points to another component's theme ID to display its theme variables
// (e.g. Drilldown.Group uses Options theme, so themeId: "Options")
themeId?: string
Comment on lines +63 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drilldown displays the token of Options in some of its subcomponents, so I implemented this functionality without the theme.ts files like in v11_6

}

type JsDocResult = {
Expand Down
16 changes: 11 additions & 5 deletions packages/__docs__/src/Document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ class Document extends Component<DocumentProps, DocumentState> {
// use PascalCase without dots (e.g. "MenuItem").
// New-theme entries are in themeVariables.newTheme.components.
const selectedId = this.state.selectedDetailsTabId
const themeKey = selectedId?.replace(/\./g, '')
const childDoc =
selectedId !== doc.id
? doc?.children?.find((value) => value.id === selectedId)
: null
// in case of some components, we need to display the theme variables of other components based on themeId (like displaying the theme variables of Options in Drillsdown.Group)
const themeKey =
childDoc?.themeId || selectedId?.replace(/\./g, '')
// @ts-ignore todo type
const newThemeEntry = themeVariables?.newTheme?.components?.[themeKey]
if (newThemeEntry) {
const componentInstance =
selectedId === doc.id ? doc?.componentInstance : childDoc?.componentInstance
if (newThemeEntry && typeof componentInstance?.generateComponentTheme !== 'function') {
// new theme - use pre-computed theme object directly
this.setState({ componentTheme: newThemeEntry })
return
Expand All @@ -90,9 +98,7 @@ class Document extends Component<DocumentProps, DocumentState> {
if (selectedId === doc.id) {
generateTheme = doc?.componentInstance?.generateComponentTheme
} else {
generateTheme = doc?.children?.find(
(value) => value.id === selectedId
)?.componentInstance?.generateComponentTheme
generateTheme = childDoc?.componentInstance?.generateComponentTheme
}
if (typeof generateTheme === 'function' && themeVariables) {
// @ts-ignore todo type
Expand Down
20 changes: 10 additions & 10 deletions packages/ui-drilldown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@
"default": "./es/exports/a.js"
},
"./v11_7": {
"src": "./src/exports/a.ts",
"types": "./types/exports/a.d.ts",
"import": "./es/exports/a.js",
"require": "./lib/exports/a.js",
"default": "./es/exports/a.js"
"src": "./src/exports/b.ts",
"types": "./types/exports/b.d.ts",
"import": "./es/exports/b.js",
"require": "./lib/exports/b.js",
"default": "./es/exports/b.js"
},
"./latest": {
"src": "./src/exports/a.ts",
"types": "./types/exports/a.d.ts",
"import": "./es/exports/a.js",
"require": "./lib/exports/a.js",
"default": "./es/exports/a.js"
"src": "./src/exports/b.ts",
"types": "./types/exports/b.d.ts",
"import": "./es/exports/b.js",
"require": "./lib/exports/b.js",
"default": "./es/exports/b.js"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('<Drilldown.Group />', () => {
</Drilldown.Page>
</Drilldown>
)
const icon = container.querySelector('svg[name="IconCheck"]')
const icon = container.querySelector('svg[name="Check"]')
const groupOption = container.querySelector('#groupOption01')

expect(icon).not.toBeInTheDocument()
Expand All @@ -380,7 +380,7 @@ describe('<Drilldown.Group />', () => {
</Drilldown.Page>
</Drilldown>
)
const icon = container.querySelector('svg[name="IconCheck"]')
const icon = container.querySelector('svg[name="Check"]')
const groupOption = container.querySelector('#groupOption01')

expect(icon).toBeInTheDocument()
Expand All @@ -397,7 +397,7 @@ describe('<Drilldown.Group />', () => {
</Drilldown.Page>
</Drilldown>
)
const icon = container.querySelector('svg[name="IconCheck"]')
const icon = container.querySelector('svg[name="Check"]')
const groupOption = container.querySelector('#groupOption01')

expect(icon).toBeInTheDocument()
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('<Drilldown.Group />', () => {
</Drilldown.Page>
</Drilldown>
)
const icons = container.querySelectorAll('svg[name="IconCheck"]')
const icons = container.querySelectorAll('svg[name="Check"]')

expect(icons.length).toBe(3)

Expand Down Expand Up @@ -486,7 +486,7 @@ describe('<Drilldown.Group />', () => {
</Drilldown>
)
const options = screen.getAllByRole('menuitemcheckbox')
const icons = container.querySelectorAll('svg')
const icons = container.querySelectorAll('svg[name="Check"]')

expect(options[0]).toHaveAttribute('aria-checked', 'true')
expect(options[1]).toHaveAttribute('aria-checked', 'false')
Expand Down
64 changes: 64 additions & 0 deletions packages/ui-drilldown/src/Drilldown/v2/DrilldownGroup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 { Component } from 'react'

import { withStyle } from '@instructure/emotion'

import { allowedProps } from './props'
import type { DrilldownGroupProps } from './props'
import { isMac, isFirefox } from '@instructure/ui-utils'

/**
---
parent: Drilldown
id: Drilldown.Group
themeId: Options
---
@module DrilldownGroup
**/
// needed for listing the available theme variables on docs page,
// we pass the themeOverrides to Options
@withStyle(null)
class DrilldownGroup extends Component<DrilldownGroupProps> {
static readonly componentId = 'Drilldown.Group'

static allowedProps = allowedProps
static defaultProps = {
disabled: false,
withoutSeparators: false,
// Firefox with NVDA does not read Drilldown.Group with role="group" correctly
// but setting role="menu" on all other platforms results in Drilldown.Group label not being read
role: !isMac() && isFirefox() ? 'menu' : 'group'
}

render() {
// this component is only used for prop validation.
// Drilldown.Group is parsed in Drilldown as an Options component.
return null
}
}

export default DrilldownGroup
export { DrilldownGroup }
134 changes: 134 additions & 0 deletions packages/ui-drilldown/src/Drilldown/v2/DrilldownGroup/props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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 React from 'react'

import type {
OtherHTMLAttributes,
OptionsTheme,
AsElementType
} from '@instructure/shared-types'
import type { WithStyleProps } from '@instructure/emotion'

import Drilldown from '../index'
import type { DrilldownOptionValue } from '../DrilldownOption/props'
import type { OptionChild, SeparatorChild } from '../props'

type GroupChildren = OptionChild | SeparatorChild

type DrilldownGroupOwnProps = {
id: string

/**
* Children of type:
* `<Drilldown.Option />`, `<Drilldown.Separator />`
*/
children?: GroupChildren | GroupChildren[] // TODO: type Children.oneOf([DrilldownOption, DrilldownSeparator])

/**
* The label of the option group.
*/
renderGroupTitle?: React.ReactNode | (() => React.ReactNode)

/**
* Hides the separators around the group.
*/
withoutSeparators?: boolean

/**
* Is the option group disabled.
*/
disabled?: boolean

/**
* The ARIA role of the element.
*/
role?: string

/**
* Element type to render as. By default, it inherits Drilldown's `as` prop.
*/
as?: AsElementType

/**
* Provides a reference to the underlying html root element
*/
elementRef?: (element: Element | null) => void

// selection props
/**
* Makes the option group selectable (with "check" icon indicators).
* Can be set to a single-select (radio) or a multi-select (checkbox) group.
*/
selectableType?: 'single' | 'multiple'

/**
* An array of the values for the selected items on initial render. Works only with "selectableType" set. If "selectableType" is "single", the array has to have 1 item.
*/
defaultSelected?: DrilldownOptionValue[]

/**
* An array of the values for the selected items. If defined, the component will act controlled and will not manage its own state. Works only with "selectableType" set.
* If "selectableType" is "single", the array has to have 1 item.
*/
selectedOptions?: DrilldownOptionValue[]

/**
* Callback fired when an option within the `<Drilldown.Group />` is selected
*/
onSelect?: (
event: React.SyntheticEvent,
args: {
value: DrilldownOptionValue[]
isSelected: boolean
selectedOption: OptionChild
drilldown: Drilldown
}
) => void
}

type PropKeys = keyof DrilldownGroupOwnProps

type AllowedPropKeys = Readonly<Array<PropKeys>>

type DrilldownGroupProps = DrilldownGroupOwnProps &
WithStyleProps<OptionsTheme, null> &
OtherHTMLAttributes<DrilldownGroupOwnProps>
const allowedProps: AllowedPropKeys = [
'id',
'children',
'renderGroupTitle',
'withoutSeparators',
'disabled',
'role',
'as',
'elementRef',
'selectableType',
'defaultSelected',
'selectedOptions',
'onSelect'
]

export type { DrilldownGroupProps, GroupChildren }
export { allowedProps }
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { vi } from 'vitest'
import userEvent from '@testing-library/user-event'
import '@testing-library/jest-dom'

import { IconCheckSolid } from '@instructure/ui-icons'
import { CheckInstUIIcon } from '@instructure/ui-icons'

import { Drilldown } from '../../index'

Expand Down Expand Up @@ -196,7 +196,7 @@ describe('<Drilldown.Option />', () => {
const icon = container.querySelector('svg')

expect(icon).toBeInTheDocument()
expect(icon).toHaveAttribute('name', 'IconArrowOpenEnd')
expect(icon).toHaveAttribute('name', 'ChevronRight')
})

it('should indicate subpage fo SR', async () => {
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('<Drilldown.Option />', () => {
<Drilldown.Page id="page0">
<Drilldown.Option
id="option1"
renderBeforeLabel={<IconCheckSolid />}
renderBeforeLabel={<CheckInstUIIcon />}
>
Option
</Drilldown.Option>
Expand All @@ -458,11 +458,11 @@ describe('<Drilldown.Option />', () => {
const icon = container.querySelector('svg')

expect(icon).toBeInTheDocument()
expect(icon).toHaveAttribute('name', 'IconCheck')
expect(icon).toHaveAttribute('name', 'Check')
})

it('as function should have option props as params', async () => {
const beforeLabelFunction = vi.fn(() => <IconCheckSolid />)
const beforeLabelFunction = vi.fn(() => <CheckInstUIIcon />)
render(
<Drilldown rootPageId="page0">
<Drilldown.Page id="page0">
Expand Down Expand Up @@ -517,7 +517,7 @@ describe('<Drilldown.Option />', () => {
<Drilldown.Page id="page0">
<Drilldown.Option
id="option1"
renderAfterLabel={<IconCheckSolid />}
renderAfterLabel={<CheckInstUIIcon />}
>
Option
</Drilldown.Option>
Expand All @@ -527,11 +527,11 @@ describe('<Drilldown.Option />', () => {
const icon = container.querySelector('svg')

expect(icon).toBeInTheDocument()
expect(icon).toHaveAttribute('name', 'IconCheck')
expect(icon).toHaveAttribute('name', 'Check')
})

it('as function should have option props as params', async () => {
const beforeLabelFunction = vi.fn(() => <IconCheckSolid />)
const beforeLabelFunction = vi.fn(() => <CheckInstUIIcon />)
render(
<Drilldown rootPageId="page0">
<Drilldown.Page id="page0">
Expand Down
Loading
Loading