Skip to content

Commit

Permalink
feat(shared-types,ui-options,ui-select): allow to change font weight …
Browse files Browse the repository at this point in the history
…of selected option item in Select

Closes: INSTUI-4394
  • Loading branch information
ToMESSKa authored and HerrTopi committed Dec 12, 2024
1 parent dee9abb commit 6818928
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/shared-types/src/ComponentThemeVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ export type OptionsItemTheme = {
descriptionLineHeight: Typography['lineHeight']
descriptionPaddingStart: string | 0
descriptionColor: Colors['contrasts']['grey4570']
fontWeightSelected: Typography['fontWeightNormal']
}

export type OptionsSeparatorTheme = {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-options/src/Options/Item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class Item extends Component<OptionsItemProps> {
role: 'listitem',
voiceoverRoleBugWorkaround: false,
beforeLabelContentVAlign: 'center',
afterLabelContentVAlign: 'center'
afterLabelContentVAlign: 'center',
isSelected: false
} as const

ref: Element | null = null
Expand Down
10 changes: 8 additions & 2 deletions packages/ui-options/src/Options/Item/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ type OptionsItemOwnProps = OptionsItemRenderProps & {
* provides a reference to the underlying html root element
*/
elementRef?: (element: Element | null) => void
/**
* Whether or not this option is selected
*/
isSelected?: boolean
}

type PropKeys = keyof OptionsItemOwnProps
Expand Down Expand Up @@ -133,7 +137,8 @@ const propTypes: PropValidators<PropKeys> = {
href: PropTypes.string,
voiceoverRoleBugWorkaround: PropTypes.bool,
elementRef: PropTypes.func,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
isSelected: PropTypes.bool
}

const allowedProps: AllowedPropKeys = [
Expand All @@ -149,7 +154,8 @@ const allowedProps: AllowedPropKeys = [
'voiceoverRoleBugWorkaround',
'href',
'elementRef',
'children'
'children',
'isSelected'
]

export type { OptionsItemProps, OptionsItemStyle, OptionsItemRenderProps }
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-options/src/Options/Item/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ const generateStyle = (
display: 'block',
fontSize: componentTheme.fontSize,
fontFamily: componentTheme.fontFamily,
fontWeight: componentTheme.fontWeight,
fontWeight: props.isSelected
? componentTheme.fontWeightSelected
: componentTheme.fontWeight,
lineHeight: componentTheme.lineHeight,
outline: 'none',
position: 'relative',
Expand Down
1 change: 1 addition & 0 deletions packages/ui-options/src/Options/Item/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const generateComponentTheme = (theme: Theme): OptionsItemTheme => {
fontFamily: typography?.fontFamily,
fontWeight: typography?.fontWeightNormal,
lineHeight: typography?.lineHeightCondensed,
fontWeightSelected: typography?.fontWeightNormal,

color: colors?.contrasts?.grey125125,
background: colors?.contrasts?.white1010,
Expand Down
1 change: 1 addition & 0 deletions packages/ui-select/src/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class Select extends Component<SelectProps> {
// should option be treated as highlighted or selected
if (isSelected) {
optionProps.variant = 'selected'
optionProps.isSelected = true
} else if (isHighlighted) {
optionProps.variant = 'highlighted'
}
Expand Down

0 comments on commit 6818928

Please sign in to comment.