Skip to content

Commit a823d51

Browse files
committed
feat(ui-view): add borderColor prop to ContextView; make borderColor accept HEX code as a string in View
Closes: INSTUI-4346
1 parent 85cbe95 commit a823d51

File tree

5 files changed

+55
-40
lines changed

5 files changed

+55
-40
lines changed

packages/ui-view/src/ContextView/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class ContextView extends Component<ContextViewProps> {
9797
stacking,
9898
style,
9999
textAlign,
100-
styles
100+
styles,
101+
borderColor
101102
} = this.props
102103

103104
return (
@@ -118,7 +119,10 @@ class ContextView extends Component<ContextViewProps> {
118119
display="block"
119120
borderRadius="medium"
120121
borderWidth="small"
121-
borderColor={background === 'default' ? 'primary' : 'transparent'}
122+
borderColor={
123+
borderColor ||
124+
(background === 'default' ? 'primary' : 'transparent')
125+
}
122126
background={background === 'default' ? 'primary' : 'primary-inverse'}
123127
withVisualDebug={debug}
124128
height={height}

packages/ui-view/src/ContextView/props.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type ContextViewOwnProps = {
6161
shadow?: Shadow
6262
stacking?: Stacking
6363
placement?: PlacementPropValues
64+
borderColor?: string
6465
}
6566

6667
type PropKeys = keyof ContextViewOwnProps
@@ -141,7 +142,13 @@ const propTypes: PropValidators<PropKeys> = {
141142
* Activate an outline around the component to make building your
142143
* layout easier
143144
*/
144-
debug: PropTypes.bool
145+
debug: PropTypes.bool,
146+
147+
/**
148+
* Sets the color of the ContextView border.
149+
* Accepts a color string value (e.g., "#FFFFFF", "red")
150+
*/
151+
borderColor: PropTypes.string
145152
}
146153

147154
const allowedProps: AllowedPropKeys = [
@@ -161,7 +168,8 @@ const allowedProps: AllowedPropKeys = [
161168
'stacking',
162169
'background',
163170
'placement',
164-
'debug'
171+
'debug',
172+
'borderColor'
165173
]
166174

167175
export type { ContextViewProps, ContextViewStyle }

packages/ui-view/src/ContextView/styles.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ const getArrowCorrections = (
126126
const getArrowPlacementVariant = (
127127
placement: PlacementPropValues,
128128
background: ContextViewProps['background'],
129-
theme: ContextViewTheme
129+
theme: ContextViewTheme,
130+
props: ContextViewProps
130131
) => {
131132
const transformedPlacement = mirrorPlacement(placement, ' ')
132133
const isInversed = background === 'inverse'
134+
const { borderColor } = props
133135

134136
if (endPlacements.includes(transformedPlacement)) {
135137
return {
@@ -140,9 +142,11 @@ const getArrowPlacementVariant = (
140142
marginTop: `calc(-1 * (${theme?.arrowSize} + ${theme?.arrowBorderWidth}))`,
141143
borderInlineEndWidth: '0',
142144
borderInlineEndColor: 'transparent',
143-
borderInlineStartColor: isInversed
144-
? theme?.arrowBorderColorInverse
145-
: theme?.arrowBorderColor,
145+
borderInlineStartColor:
146+
borderColor ||
147+
(isInversed
148+
? theme?.arrowBorderColorInverse
149+
: theme?.arrowBorderColor),
146150
borderTopColor: 'transparent',
147151
borderBottomColor: 'transparent',
148152
borderInlineStartWidth: theme?.arrowSize
@@ -173,9 +177,11 @@ const getArrowPlacementVariant = (
173177
marginTop: `calc(-1 * (${theme?.arrowSize} + ${theme?.arrowBorderWidth}))`,
174178
borderInlineStartWidth: '0',
175179
borderInlineStartColor: 'transparent',
176-
borderInlineEndColor: isInversed
177-
? theme?.arrowBorderColorInverse
178-
: theme?.arrowBorderColor,
180+
borderInlineEndColor:
181+
borderColor ||
182+
(isInversed
183+
? theme?.arrowBorderColorInverse
184+
: theme?.arrowBorderColor),
179185
borderTopColor: 'transparent',
180186
borderBottomColor: 'transparent',
181187
borderInlineEndWidth: theme?.arrowSize
@@ -261,7 +267,7 @@ const generateStyle = (
261267
componentTheme: ContextViewTheme,
262268
props: ContextViewProps
263269
): ContextViewStyle => {
264-
const { placement, background } = props
270+
const { placement, background, borderColor } = props
265271

266272
const arrowBaseStyles = {
267273
content: '""',
@@ -282,7 +288,8 @@ const generateStyle = (
282288
const arrowPlacementVariant = getArrowPlacementVariant(
283289
placement!,
284290
background,
285-
componentTheme
291+
componentTheme,
292+
props
286293
)
287294

288295
return {
@@ -301,7 +308,7 @@ const generateStyle = (
301308
...arrowBaseStyles,
302309
display: 'block',
303310
borderWidth: `calc(${componentTheme?.arrowSize} + ${componentTheme?.arrowBorderWidth})`,
304-
borderColor: arrowBackGroundVariants[background!],
311+
borderColor: borderColor || arrowBackGroundVariants[background!],
305312
...arrowPlacementVariant.main,
306313
...getArrowCorrections(placement!, componentTheme),
307314
'&::after': {

packages/ui-view/src/View/props.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ import type {
4747
StyleObject
4848
} from '@instructure/emotion'
4949

50+
type BorderColor =
51+
| string
52+
| 'transparent'
53+
| 'primary'
54+
| 'secondary'
55+
| 'brand'
56+
| 'info'
57+
| 'success'
58+
| 'warning'
59+
| 'alert'
60+
| 'danger'
61+
5062
type ViewOwnProps = {
5163
/**
5264
* The element to render as the component root, `span` by default
@@ -84,18 +96,10 @@ type ViewOwnProps = {
8496
*/
8597
textAlign?: 'start' | 'center' | 'end'
8698
/**
87-
* Sets the color of the View border
99+
* Sets the color of the View border.
100+
* Accepts a color string value (e.g., "#FFFFFF", "red") or one of the predefined theme color options.
88101
*/
89-
borderColor?:
90-
| 'transparent'
91-
| 'primary'
92-
| 'secondary'
93-
| 'brand'
94-
| 'info'
95-
| 'success'
96-
| 'warning'
97-
| 'alert'
98-
| 'danger'
102+
borderColor?: BorderColor
99103
/**
100104
* Designates the background style of the `<View />`
101105
*/
@@ -234,17 +238,7 @@ const propTypes: PropValidators<PropKeys> = {
234238
textAlign: PropTypes.oneOf(['start', 'center', 'end']),
235239
borderWidth: ThemeablePropTypes.borderWidth,
236240
borderRadius: ThemeablePropTypes.borderRadius,
237-
borderColor: PropTypes.oneOf([
238-
'transparent',
239-
'primary',
240-
'secondary',
241-
'brand',
242-
'info',
243-
'success',
244-
'warning',
245-
'alert',
246-
'danger'
247-
]),
241+
borderColor: PropTypes.string,
248242
background: PropTypes.oneOf([
249243
'transparent',
250244
'primary',
@@ -321,4 +315,4 @@ const allowedProps: AllowedPropKeys = [
321315
]
322316

323317
export { propTypes, allowedProps }
324-
export type { ViewProps, ViewOwnProps, ViewStyle }
318+
export type { ViewProps, ViewOwnProps, ViewStyle, BorderColor }

packages/ui-view/src/View/styles.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type {
3636
PartialRecord,
3737
ViewTheme
3838
} from '@instructure/shared-types'
39-
import type { ViewProps, ViewStyle } from './props'
39+
import type { ViewProps, ViewStyle, BorderColor } from './props'
4040

4141
const getBorderStyle = ({
4242
borderRadius,
@@ -468,7 +468,7 @@ const generateStyle = (
468468
end: { textAlign: 'end' }
469469
}
470470

471-
const borderColorVariants = {
471+
const borderColorVariants: Record<BorderColor, { borderColor: string }> = {
472472
transparent: {
473473
borderColor: componentTheme.borderColorTransparent
474474
},
@@ -596,7 +596,9 @@ const generateStyle = (
596596
...(withBorder(props)
597597
? {
598598
borderStyle: componentTheme.borderStyle,
599-
...borderColorVariants[borderColor!]
599+
...(borderColorVariants[borderColor!] || {
600+
borderColor: borderColor
601+
})
600602
}
601603
: {}),
602604
...(shouldUseFocusStyles ? focusStyles : {})

0 commit comments

Comments
 (0)