@instructure/ui-view 10.16.4-snapshot-4 → 10.16.4-snapshot-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,7 +29,6 @@ import {
29
29
  mirrorShorthandCorners
30
30
  } from '@instructure/emotion'
31
31
  import { pickProps } from '@instructure/ui-react-utils'
32
- import { logError as error } from '@instructure/console'
33
32
 
34
33
  import type {
35
34
  OtherHTMLAttributes,
@@ -37,6 +36,7 @@ import type {
37
36
  ViewTheme
38
37
  } from '@instructure/shared-types'
39
38
  import type { ViewProps, ViewStyle, BorderColor } from './props'
39
+ import { alpha } from '@instructure/ui-color-utils'
40
40
 
41
41
  const getBorderStyle = ({
42
42
  borderRadius,
@@ -209,35 +209,8 @@ const getFocusRingRadius = (
209
209
  return `${baseRadiusStyle}None` as FocusRingRadius
210
210
  }
211
211
 
212
- const getFocusOutline = (props: ViewProps) => {
213
- const {
214
- position,
215
- display,
216
- focusPosition,
217
- withFocusOutline: shouldDisplayFocusOutline
218
- } = props
219
-
220
- if (typeof shouldDisplayFocusOutline === 'undefined') {
221
- return shouldDisplayFocusOutline
222
- }
223
-
224
- if (shouldDisplayFocusOutline) {
225
- error(
226
- display === 'inline' || position === 'relative',
227
- '[View] the focus outline will only show if the `position` prop is `relative`.'
228
- )
229
- error(
230
- display !== 'inline' || focusPosition === 'inset',
231
- '[View] when display is set to `inline` the focus outline will only show if `focusPosition` is set to `inset`.'
232
- )
233
- }
234
-
235
- return shouldDisplayFocusOutline
236
- }
237
-
238
212
  const withBorder = (props: ViewProps) => {
239
213
  const { borderWidth } = props
240
-
241
214
  return borderWidth && borderWidth !== '0' && borderWidth !== 'none'
242
215
  }
243
216
 
@@ -245,26 +218,23 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
245
218
  const {
246
219
  focusColor,
247
220
  focusPosition,
248
- position,
249
221
  shouldAnimateFocus,
250
222
  borderRadius,
251
- focusRingBorderRadius
223
+ focusRingBorderRadius,
224
+ withFocusOutline,
225
+ focusWithin
252
226
  } = props
253
- const focusOutline = getFocusOutline(props)
254
- const shouldUseBrowserFocus = typeof focusOutline === 'undefined'
255
227
 
228
+ const focusPos =
229
+ focusPosition == 'offset' || focusPosition == 'inset'
230
+ ? focusPosition
231
+ : 'offset'
256
232
  const focusPositionVariants = {
257
233
  offset: {
258
- top: `calc(${componentTheme.focusOutlineOffset} * -1)`,
259
- left: `calc(${componentTheme.focusOutlineOffset} * -1)`,
260
- right: `calc(${componentTheme.focusOutlineOffset} * -1)`,
261
- bottom: `calc(${componentTheme.focusOutlineOffset}* -1)`
234
+ outlineOffset: `calc(${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth})`
262
235
  },
263
236
  inset: {
264
- top: `calc(${componentTheme.focusOutlineInset} * -1)`,
265
- left: `calc(${componentTheme.focusOutlineInset} * -1)`,
266
- right: `calc(${componentTheme.focusOutlineInset} * -1)`,
267
- bottom: `calc(${componentTheme.focusOutlineInset} * -1)`
237
+ outlineOffset: `calc(${componentTheme.focusOutlineInset} - ${componentTheme.focusOutlineWidth})`
268
238
  }
269
239
  }
270
240
  const focusColorVariants = {
@@ -274,104 +244,77 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
274
244
  danger: componentTheme.focusColorDanger
275
245
  }
276
246
 
277
- if (position === 'relative') {
278
- const focusRingRadius = getFocusRingRadius(borderRadius, props)
279
- const focusRingVariants: PartialRecord<FocusRingRadius, string | 0> = {
280
- 'focusRing--radiusInherit': 'inherit',
281
- 'focusRing--radiusNone': 0
282
- }
283
- const borderRadiusByOffset: {
284
- [k in NonNullable<ViewProps['focusPosition']>]: PartialRecord<
285
- FocusRingRadius,
286
- { borderRadius: string }
287
- >
288
- } = {
289
- offset: {
290
- 'focusRing--radiusSmall': {
291
- borderRadius: `calc(${componentTheme.borderRadiusSmall} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
292
- },
293
- 'focusRing--radiusMedium': {
294
- borderRadius: `calc(${componentTheme.borderRadiusMedium} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
295
- },
296
- 'focusRing--radiusLarge': {
297
- borderRadius: `calc(${componentTheme.borderRadiusLarge} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
298
- },
299
- 'focusRing--radiusCustom': {
300
- borderRadius: `calc(${focusRingBorderRadius} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
301
- }
247
+ const focusRingRadius = getFocusRingRadius(borderRadius, props)
248
+ const focusRingVariants: PartialRecord<FocusRingRadius, string | 0> = {
249
+ 'focusRing--radiusInherit': 'inherit',
250
+ 'focusRing--radiusNone': 0
251
+ }
252
+ const borderRadiusByOffset: {
253
+ [k in NonNullable<ViewProps['focusPosition']>]: PartialRecord<
254
+ FocusRingRadius,
255
+ { borderRadius: string }
256
+ >
257
+ } = {
258
+ offset: {
259
+ 'focusRing--radiusSmall': {
260
+ borderRadius: `calc(${componentTheme.borderRadiusSmall} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
302
261
  },
303
- inset: {
304
- 'focusRing--radiusSmall': {
305
- borderRadius: `calc(${componentTheme.borderRadiusSmall} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
306
- },
307
- 'focusRing--radiusMedium': {
308
- borderRadius: `calc(${componentTheme.borderRadiusMedium} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
309
- },
310
- 'focusRing--radiusLarge': {
311
- borderRadius: `calc(${componentTheme.borderRadiusLarge} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
312
- },
313
- 'focusRing--radiusCustom': {
314
- borderRadius: `calc(${focusRingBorderRadius} - (${componentTheme.focusOutlineOffset} + ${componentTheme.focusOutlineWidth}))`
315
- }
262
+ 'focusRing--radiusMedium': {
263
+ borderRadius: `calc(${componentTheme.borderRadiusMedium} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
264
+ },
265
+ 'focusRing--radiusLarge': {
266
+ borderRadius: `calc(${componentTheme.borderRadiusLarge} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
267
+ },
268
+ 'focusRing--radiusCustom': {
269
+ borderRadius: `calc(${focusRingBorderRadius} + (${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth}))`
316
270
  }
317
- }
318
-
319
- return {
320
- '&::before': {
321
- pointerEvents: 'none',
322
- content: '""',
323
- position: 'absolute',
324
- borderStyle: componentTheme.focusOutlineStyle,
325
- borderWidth: componentTheme.focusOutlineWidth,
326
- borderColor: focusColorVariants[focusColor!],
327
- opacity: 0,
328
- borderRadius: focusRingVariants[focusRingRadius],
329
- ...borderRadiusByOffset[focusPosition!][focusRingRadius],
330
- ...focusPositionVariants[focusPosition!],
331
- ...(shouldAnimateFocus
332
- ? {
333
- transition: 'all 0.2s',
334
- transform: 'scale(0.95)'
335
- }
336
- : {}),
337
- ...(focusOutline
338
- ? {
339
- opacity: 1,
340
- transform: 'scale(1)'
341
- }
342
- : {})
271
+ },
272
+ inset: {
273
+ 'focusRing--radiusSmall': {
274
+ borderRadius: `calc(${componentTheme.borderRadiusSmall} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
343
275
  },
344
- '&:focus': {
345
- outline: 'none',
346
- '&::before': {
347
- ...(shouldUseBrowserFocus
348
- ? {
349
- opacity: 1,
350
- transform: 'scale(1)'
351
- }
352
- : {})
353
- }
276
+ 'focusRing--radiusMedium': {
277
+ borderRadius: `calc(${componentTheme.borderRadiusMedium} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
278
+ },
279
+ 'focusRing--radiusLarge': {
280
+ borderRadius: `calc(${componentTheme.borderRadiusLarge} - (${componentTheme.focusOutlineInset} + ${componentTheme.focusOutlineWidth}))`
281
+ },
282
+ 'focusRing--radiusCustom': {
283
+ borderRadius: `calc(${focusRingBorderRadius} - (${componentTheme.focusOutlineOffset} + ${componentTheme.focusOutlineWidth}))`
354
284
  }
355
285
  }
356
286
  }
357
-
358
287
  return {
359
- '&::before': {
360
- borderStyle: 'none'
361
- },
362
- outlineStyle: 'none',
363
- outlineColor: focusColorVariants[focusColor!],
364
- ...(focusOutline
288
+ outlineOffset: '-0.8rem', // value when not in focus, its invisible
289
+ outlineColor: alpha(focusColorVariants[focusColor!], 0),
290
+ outlineStyle: componentTheme.focusOutlineStyle,
291
+ outlineWidth: componentTheme.focusOutlineWidth,
292
+ borderRadius: focusRingVariants[focusRingRadius], // inherit or none
293
+ ...borderRadiusByOffset[focusPos][focusRingRadius], // border radius value
294
+ ...(shouldAnimateFocus
365
295
  ? {
366
- outlineWidth: componentTheme.focusOutlineWidth,
367
- outlineStyle: componentTheme.focusOutlineStyle
296
+ transition: 'outline-color 0.2s, outline-offset 0.25s'
297
+ }
298
+ : {}),
299
+ ...(withFocusOutline
300
+ ? {
301
+ ...focusPositionVariants[focusPos],
302
+ outlineColor: focusColorVariants[focusColor!]
368
303
  }
369
304
  : {}),
370
305
  '&:focus': {
371
- ...(shouldUseBrowserFocus
306
+ ...(typeof withFocusOutline === 'undefined'
307
+ ? {
308
+ ...focusPositionVariants[focusPos],
309
+ outlineColor: focusColorVariants[focusColor!]
310
+ }
311
+ : {})
312
+ },
313
+ '&:focus-within': {
314
+ ...(focusWithin
372
315
  ? {
373
- outlineWidth: componentTheme.focusOutlineWidth,
374
- outlineStyle: componentTheme.focusOutlineStyle
316
+ ...focusPositionVariants[focusPos],
317
+ outlineColor: focusColorVariants[focusColor!]
375
318
  }
376
319
  : {})
377
320
  }
@@ -385,7 +328,6 @@ const getFocusStyles = (props: ViewProps, componentTheme: ViewTheme) => {
385
328
  * Generates the style object from the theme and provided additional information
386
329
  * @param {Object} componentTheme The theme variable object.
387
330
  * @param {Object} props the props of the component, the style is applied to
388
- * @param {Object} extraArgs
389
331
  * @return {Object} The final style object, which will be used in the component
390
332
  */
391
333
  const generateStyle = (
@@ -399,7 +341,6 @@ const generateStyle = (
399
341
  padding,
400
342
  position,
401
343
  display,
402
- focusPosition,
403
344
  textAlign,
404
345
  borderColor,
405
346
  background,
@@ -444,10 +385,6 @@ const generateStyle = (
444
385
  insetInlineStart
445
386
  })
446
387
 
447
- const shouldUseFocusStyles =
448
- position === 'relative' ||
449
- (display === 'inline' && focusPosition === 'inset')
450
-
451
388
  const displayVariants = {
452
389
  inline: {
453
390
  label: 'view--inline',
@@ -583,7 +520,6 @@ const generateStyle = (
583
520
  }
584
521
 
585
522
  const focusStyles = getFocusStyles(props, componentTheme)
586
-
587
523
  return {
588
524
  view: {
589
525
  label: 'view',
@@ -602,7 +538,8 @@ const generateStyle = (
602
538
  overscrollBehavior: overscrollBehavior ? overscrollBehavior : 'auto',
603
539
  ...(withVisualDebug
604
540
  ? {
605
- outline: `0.0625rem dashed ${componentTheme.debugOutlineColor}`
541
+ //outline: `0.0625rem dashed ${componentTheme.debugOutlineColor}`
542
+ boxShadow: `0 0 0 1px ${componentTheme.debugOutlineColor}`
606
543
  }
607
544
  : {}),
608
545
  ...(withBorder(props)
@@ -613,7 +550,7 @@ const generateStyle = (
613
550
  })
614
551
  }
615
552
  : {}),
616
- ...(shouldUseFocusStyles ? focusStyles : {})
553
+ ...focusStyles
617
554
  },
618
555
  inlineStyles: {
619
556
  //every '&' symbol will add another class to the rule, so it will be stronger