-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: support icons inside of S2 DisclosureTitle #9934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c943180
2c6035d
86db471
d2e4856
ee87077
20fb8e7
425fa53
f729c1e
5c134e7
e96cee9
ae69bf4
5605e6f
0d182c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,12 +23,13 @@ import { | |
| baseColor, | ||
| centerPadding, | ||
| focusRing, | ||
| fontRelative, | ||
| lightDark, | ||
| space, | ||
| style | ||
| } from '../style' with {type: 'macro'}; | ||
| import {Button} from 'react-aria-components/Button'; | ||
| import {CenterBaseline} from './CenterBaseline'; | ||
| import {CenterBaseline, centerBaseline} from './CenterBaseline'; | ||
|
|
||
| import Chevron from '../ui-icons/Chevron'; | ||
|
|
||
|
|
@@ -43,7 +44,9 @@ import { | |
| import {filterDOMProps} from 'react-aria/filterDOMProps'; | ||
| import {getAllowedOverrides, StyleProps, UnsafeStyles} from './style-utils' with {type: 'macro'}; | ||
| import {Heading} from 'react-aria-components/Heading'; | ||
| import {IconContext} from './Icon'; | ||
| import React, {createContext, forwardRef, ReactNode, useContext} from 'react'; | ||
| import {Text, TextContext} from './Content'; | ||
| import {useDOMRef} from './useDOMRef'; | ||
| import {useLocale} from 'react-aria/I18nProvider'; | ||
| import {useSpectrumContextProps} from './useSpectrumContextProps'; | ||
|
|
@@ -171,12 +174,16 @@ const buttonStyles = style({ | |
| } | ||
| }, | ||
| lineHeight: 'ui', | ||
| display: 'flex', | ||
| flexGrow: 1, | ||
| display: 'grid', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine, but any particular reason for switching to grid?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it was either use grid or use flex and wrap the icon and text within another div. i can't use |
||
| gridTemplateAreas: ['expand-button icon label'], | ||
| gridTemplateColumns: ['auto', 'auto', 'minmax(0, 1fr)'], | ||
| alignItems: 'baseline', | ||
| paddingX: 'calc(self(minHeight) * 3/8 - 1px)', | ||
| '--spacingGap': { | ||
| type: 'marginEnd', | ||
| value: 'calc(self(minHeight) * 3/8 - 1px)' | ||
| }, | ||
| paddingX: '--spacingGap', | ||
| paddingY: centerPadding(), | ||
| gap: 'calc(self(minHeight) * 3/8 - 1px)', | ||
| minHeight: { | ||
| // compact is equivalent to 'control', but other densities have more padding. | ||
| size: { | ||
|
|
@@ -238,8 +245,7 @@ const chevronStyles = style({ | |
| '--iconPrimary': { | ||
| type: 'fill', | ||
| value: 'currentColor' | ||
| }, | ||
| flexShrink: 0 | ||
| } | ||
| }); | ||
|
|
||
| const InternalDisclosureHeader = createContext<{} | null>(null); | ||
|
|
@@ -306,10 +312,29 @@ export const DisclosureTitle = forwardRef(function DisclosureTitle( | |
| <Button | ||
| className={renderProps => buttonStyles({...renderProps, size, density, isQuiet})} | ||
| slot="trigger"> | ||
| <CenterBaseline> | ||
| <CenterBaseline styles={style({gridArea: 'expand-button', marginEnd: '--spacingGap'})}> | ||
| <Chevron size={size} className={chevronStyles({isExpanded, isRTL})} aria-hidden="true" /> | ||
| </CenterBaseline> | ||
| {props.children} | ||
| <Provider | ||
| values={[ | ||
| [ | ||
| IconContext, | ||
| { | ||
| render: centerBaseline({ | ||
| slot: 'icon', | ||
| styles: style({ | ||
| gridArea: 'icon', | ||
| marginEnd: 'text-to-visual', | ||
| '--iconPrimary': {type: 'fill', value: 'currentColor'} | ||
| }) | ||
| }), | ||
| styles: style({size: fontRelative(16)}) | ||
| } | ||
| ], | ||
| [TextContext, {styles: style({gridArea: 'label'})}] | ||
| ]}> | ||
| {typeof props.children === 'string' ? <Text>{props.children}</Text> : props.children} | ||
| </Provider> | ||
| </Button> | ||
| </Heading> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this removal seems undesireable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it should be fine? the parent has flexGrow 1: and button is the only flex child and since it has
width: 'full, it with always take up the parent's full width