@codeleap/web 3.3.2 → 3.5.0

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.
Files changed (59) hide show
  1. package/package.json +3 -1
  2. package/src/components/ActionIcon/index.tsx +49 -30
  3. package/src/components/ActionIcon/styles.ts +8 -5
  4. package/src/components/ActivityIndicator/index.tsx +6 -5
  5. package/src/components/Badge/index.tsx +135 -0
  6. package/src/components/Badge/styles.ts +15 -0
  7. package/src/components/Button/index.tsx +79 -69
  8. package/src/components/Button/styles.ts +10 -14
  9. package/src/components/Checkbox/index.tsx +9 -3
  10. package/src/components/Collapse/index.tsx +6 -3
  11. package/src/components/Drawer/index.tsx +72 -44
  12. package/src/components/Drawer/styles.ts +11 -3
  13. package/src/components/EmptyPlaceholder/index.tsx +135 -0
  14. package/src/components/EmptyPlaceholder/styles.ts +16 -0
  15. package/src/components/Grid/index.tsx +169 -0
  16. package/src/components/Grid/styles.ts +10 -0
  17. package/src/components/Grid/types.ts +24 -0
  18. package/src/components/Icon/index.tsx +7 -4
  19. package/src/components/InputBase/styles.ts +8 -56
  20. package/src/components/InputBase/utils.ts +63 -0
  21. package/src/components/List/ListLayout.tsx +98 -0
  22. package/src/components/List/PaginationIndicator.tsx +102 -0
  23. package/src/components/List/index.tsx +104 -91
  24. package/src/components/List/styles.ts +17 -5
  25. package/src/components/List/types.ts +51 -0
  26. package/src/components/List/useInfiniteScroll.ts +113 -0
  27. package/src/components/LoadingOverlay/index.tsx +5 -3
  28. package/src/components/Modal/index.tsx +30 -29
  29. package/src/components/NumberIncrement/index.tsx +3 -2
  30. package/src/components/Overlay/index.tsx +12 -2
  31. package/src/components/Pager/index.tsx +5 -1
  32. package/src/components/RadioInput/index.tsx +4 -3
  33. package/src/components/SearchInput/index.tsx +93 -0
  34. package/src/components/SegmentedControl/SegmentedControlOption.tsx +15 -9
  35. package/src/components/SegmentedControl/index.tsx +12 -5
  36. package/src/components/Select/index.tsx +18 -14
  37. package/src/components/Select/styles.ts +4 -3
  38. package/src/components/Select/types.ts +4 -3
  39. package/src/components/Slider/index.tsx +3 -2
  40. package/src/components/Switch/index.tsx +4 -2
  41. package/src/components/Text/index.tsx +98 -25
  42. package/src/components/Text/styles.ts +4 -4
  43. package/src/components/TextInput/index.tsx +6 -15
  44. package/src/components/Tooltip/index.tsx +163 -131
  45. package/src/components/Tooltip/styles.ts +13 -9
  46. package/src/components/Touchable/index.tsx +88 -26
  47. package/src/components/Touchable/styles.ts +4 -6
  48. package/src/components/View/index.tsx +1 -1
  49. package/src/components/components.ts +5 -1
  50. package/src/components/defaultStyles.ts +10 -3
  51. package/src/index.ts +2 -0
  52. package/src/lib/hooks.ts +27 -13
  53. package/src/lib/index.ts +4 -1
  54. package/src/lib/useBreakpointMatch.ts +33 -0
  55. package/src/lib/usePopState.ts +30 -0
  56. package/src/lib/useSearchParams.ts +54 -0
  57. package/src/lib/utils/stopPropagation.ts +3 -3
  58. package/src/types/index.ts +1 -1
  59. package/src/types/utility.ts +4 -0
@@ -1,155 +1,187 @@
1
- /** @jsx jsx */
2
- import { CSSObject, jsx } from '@emotion/react'
1
+ import React, { useState } from 'react'
3
2
  import {
4
- ComponentVariants,
5
- useBooleanToggle,
6
- useDefaultComponentStyle,
7
- useDebounce,
8
- } from '@codeleap/common'
9
- import { ReactNode } from 'react'
10
- import { View } from '../View'
11
-
12
- import { StylesOf } from '../../types/utility'
13
- import { Touchable } from '../Touchable'
14
- import { useClickOutside } from '../../lib/hooks'
3
+ Provider as TooltipContainer,
4
+ Root as TooltipWrapper,
5
+ Trigger as TooltipTrigger,
6
+ Portal as TooltipPortal,
7
+ Content as TooltipContent,
8
+ Arrow as TooltipArrow,
9
+ TooltipProps as PrimitiveTooltipProps,
10
+ TooltipContentProps,
11
+ TooltipPortalProps,
12
+ TooltipArrowProps,
13
+ TooltipTriggerProps,
14
+ TooltipProviderProps,
15
+ } from '@radix-ui/react-tooltip'
16
+
17
+ import { AnyFunction, ComponentVariants, StylesOf, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
15
18
  import { TooltipComposition, TooltipPresets } from './styles'
19
+ import { ComponentCommonProps, ComponentWithDefaultProps } from '../../types/utility'
20
+ import { View, ViewProps } from '../View'
16
21
 
17
- type TooltipPosition = 'left' | 'top' | 'bottom' | 'right'
18
-
19
- const arrowPositionStyles = {
20
- left: {
21
- right: `100%`,
22
- top: '50%',
23
- transform: 'translate(50%,-50%)',
24
- borderRight: 'none',
25
- borderTop: 'none',
26
- },
27
- right: {
28
- left: `100%`,
29
- top: '50%',
30
- transform: 'translate(-50%,-50%)',
31
- borderLeft: 'none',
32
- borderBottom: 'none',
33
- },
34
- bottom: {
35
- left: '50%',
36
- top: `100%`,
37
- transform: 'translate(-50%,-50%)',
38
- borderTop: 'none',
39
- borderLeft: 'none',
40
- },
41
- top: {
42
- left: '50%',
43
- bottom: `100%`,
44
- transform: 'translate(-50%,50%)',
45
- borderBottom: 'none',
46
- borderRight: 'none',
47
- },
22
+ type TooltipComponentProps = {
23
+ contentProps?: TooltipContentProps
24
+ portalProps?: TooltipPortalProps
25
+ arrowProps?: TooltipArrowProps
26
+ triggerProps?: TooltipTriggerProps
27
+ providerProps?: TooltipProviderProps
48
28
  }
49
29
 
50
- const tooltipPositionStyles = {
51
- left: (arrow = 0, visible = false) => ({
52
- right: `calc(100% + ${arrow}px)`,
53
- top: '50%',
54
- transform: `translate(0%,-50%) scale(${visible ? '1' : '0'})`,
55
- }),
56
- right: (arrow = 0, visible = false) => ({
57
- left: `calc(100% + ${arrow}px)`,
58
- top: '50%',
59
- transform: `translate(0%,-50%) scale(${visible ? '1' : '0'})`,
60
- }),
61
- bottom: (arrow = 0, visible = false) => ({
62
- left: '50%',
63
- top: `calc(100% + ${arrow}px)`,
64
- transform: `translate(-50%,0%) scale(${visible ? '1' : '0'})`,
65
- }),
66
- top: (arrow = 0, visible = false) => ({
67
- left: '50%',
68
- bottom: `calc(100% + ${arrow}px)`,
69
- transform: `translate(-50%,0%) scale(${visible ? '1' : '0'})`,
70
- }),
30
+ export type TooltipProps = PrimitiveTooltipProps & TooltipComponentProps & {
31
+ toggle?: AnyFunction
32
+ visible?: boolean
33
+ content: React.ReactNode | ((props: TooltipProps & { variantsStyles: StylesOf<TooltipComposition> }) => JSX.Element)
34
+ triggerWrapper?: React.ReactNode
35
+ triggerWrapperProps?: Partial<ViewProps<'div'>>
36
+ styles?: StylesOf<TooltipComposition>
37
+ side?: 'left' | 'right' | 'bottom' | 'top'
38
+ openOnPress?: boolean
39
+ openOnHover?: boolean
40
+ disabled?: boolean
41
+ delayDuration?: number
42
+ onOpen?: AnyFunction
43
+ onClose?: AnyFunction
44
+ onValueChange?: (value: boolean) => void
45
+ onHover?: (hoverType: 'enter' | 'leave', value: boolean) => void
46
+ onPress?: (value: boolean) => void
47
+ children?: React.ReactNode
48
+ } & ComponentVariants<typeof TooltipPresets> & ComponentCommonProps
49
+
50
+ const defaultProps: Partial<TooltipProps> = {
51
+ openOnPress: true,
52
+ openOnHover: true,
53
+ disabled: false,
54
+ delayDuration: 0,
55
+ side: 'bottom',
56
+ triggerWrapper: View,
71
57
  }
72
58
 
73
- export type TooltipProps = React.PropsWithChildren<{
74
- position: TooltipPosition
75
- styles?: StylesOf<TooltipComposition>
76
- showOn?: 'click' | 'hover'
77
- content?: string | ReactNode
78
- } & ComponentVariants<typeof TooltipPresets>
79
- >
80
- const invert = (pos) => {
81
- switch (pos) {
82
- case 'left':
83
- return 'right'
84
- case 'right':
85
- return 'left'
86
- case 'top':
87
- return 'bottom'
88
- case 'bottom':
89
- return 'top'
59
+ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipProps) => {
60
+ const allProps = {
61
+ ...Tooltip.defaultProps,
62
+ ...props,
90
63
  }
91
- }
92
64
 
93
- export const Tooltip = (props:TooltipProps) => {
94
65
  const {
66
+ toggle: _toggle = null,
67
+ visible: _visible = null,
95
68
  children,
96
- position = 'top',
97
- styles,
98
- variants,
99
- responsiveVariants,
100
- showOn,
101
- content,
102
- } = props
69
+ content: Content,
70
+ triggerWrapperProps = {},
71
+ triggerWrapper: TriggerWrapper,
72
+ side,
73
+ disabled,
74
+ delayDuration,
75
+ openOnPress,
76
+ openOnHover,
77
+ onOpen,
78
+ onClose,
79
+ onValueChange,
80
+ onHover,
81
+ onPress,
82
+ contentProps = {},
83
+ portalProps = {},
84
+ arrowProps = {},
85
+ triggerProps = {},
86
+ providerProps = {},
87
+ variants = [],
88
+ responsiveVariants = {},
89
+ styles = {},
90
+ ...rest
91
+ } = allProps
103
92
 
104
- const [isVisible, setVisible] = useBooleanToggle(false)
105
-
106
- const [debouncedVisible] = useDebounce(isVisible, 100)
107
- const arrowPos = arrowPositionStyles[invert(position)]
108
-
109
- const variantStyles = useDefaultComponentStyle('Tooltip', {
93
+ const variantsStyles = useDefaultComponentStyle<'u:Tooltip', typeof TooltipPresets>('u:Tooltip', {
110
94
  responsiveVariants,
111
95
  variants,
112
96
  styles,
113
97
  })
114
98
 
115
- const style = {
116
- transition: 'transform 0.2s ease',
117
- '&:after': {
118
- ...variantStyles.arrow,
119
- ...arrowPos,
120
- transform: arrowPos.transform + ' rotate(45deg)',
121
- },
122
- ...tooltipPositionStyles[position](10, debouncedVisible),
123
- ...variantStyles.bubble,
124
- } as CSSObject
125
-
126
- const wrapperRef = useClickOutside(
127
- () => {
128
- if (isVisible) {
129
- setVisible(false)
130
- }
131
- },
132
- )
99
+ const hasStateProps = !TypeGuards.isNil(_visible) && TypeGuards.isFunction(_toggle)
133
100
 
134
- if (showOn === 'click') {
135
- return (
136
- <Touchable
137
- onPress={() => setVisible()}
138
- ref={wrapperRef}
139
- css={variantStyles.wrapper}
140
- >
141
- <View css={style}>{content}</View>
142
- {children}
143
- </Touchable>
144
- )
101
+ const [visible, toggle] = hasStateProps ? [_visible, _toggle] : useState(false)
102
+
103
+ const tooltipDirectionStyle = React.useMemo(() => {
104
+ return side ? variantsStyles[`wrapper:${side}`] : variantsStyles.wrapper
105
+ }, [side, variantsStyles])
106
+
107
+ function handleToggle(_value: boolean, isToggle = true) {
108
+ if (disabled) return
109
+
110
+ if (_value === true) {
111
+ onOpen?.()
112
+ } else {
113
+ onClose?.()
114
+ }
115
+
116
+ if (isToggle) toggle(_value)
117
+
118
+ if (TypeGuards.isFunction(onValueChange)) onValueChange?.(_value)
119
+ }
120
+
121
+ const onOpenChange = React.useCallback((_open: boolean) => {
122
+ handleToggle(_open, false)
123
+ }, [handleToggle])
124
+
125
+ const _onHover = (type: 'enter' | 'leave') => {
126
+ if (!openOnHover || disabled) return
127
+
128
+ const value = !visible
129
+
130
+ if (type === 'leave' && visible === false) return
131
+
132
+ handleToggle(value)
133
+ if (TypeGuards.isFunction(onHover)) onHover?.(type, value)
134
+ }
135
+
136
+ const _onPress = () => {
137
+ if (!openOnPress || disabled) return
138
+
139
+ const value = !visible
140
+
141
+ handleToggle(value)
142
+ if (TypeGuards.isFunction(onPress)) onPress?.(value)
145
143
  }
146
144
 
147
145
  return (
148
- <View onHover={setVisible} ref={wrapperRef} css={variantStyles.wrapper}>
149
- <View css={style}>{content}</View>
150
- {children}
151
- </View>
146
+ <TooltipContainer {...providerProps}>
147
+ <TooltipWrapper
148
+ delayDuration={delayDuration}
149
+ open={visible}
150
+ onOpenChange={onOpenChange}
151
+ {...rest}
152
+ >
153
+ <TooltipTrigger
154
+ onClick={_onPress}
155
+ onMouseEnter={() => _onHover('enter')}
156
+ onMouseLeave={() => _onHover('leave')}
157
+ asChild
158
+ {...triggerProps}
159
+ >
160
+ <TriggerWrapper {...allProps as any} {...triggerWrapperProps}>
161
+ {children}
162
+ </TriggerWrapper>
163
+ </TooltipTrigger>
164
+ <TooltipPortal {...portalProps}>
165
+ <TooltipContent css={[tooltipDirectionStyle, variantsStyles.wrapper]} sideOffset={2} side={side} {...contentProps}>
166
+ {
167
+ TypeGuards.isFunction(Content)
168
+ ? <Content
169
+ {...allProps}
170
+ visible={visible}
171
+ toggle={toggle}
172
+ variantsStyles={variantsStyles}
173
+ />
174
+ : Content
175
+ }
176
+ <TooltipArrow {...arrowProps} />
177
+ </TooltipContent>
178
+ </TooltipPortal>
179
+ </TooltipWrapper>
180
+
181
+ </TooltipContainer>
152
182
  )
153
183
  }
154
184
 
155
- export * from './styles'
185
+ Tooltip.defaultProps = defaultProps
186
+
187
+ export * from './styles'
@@ -1,9 +1,13 @@
1
- import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
2
-
3
- export type TooltipComposition = "wrapper" | "arrow" | "bubble"
4
-
5
- const createTooltipStyle = createDefaultVariantFactory<TooltipComposition>()
6
-
7
- export const TooltipPresets = includePresets((styles) => createTooltipStyle(() => ({
8
- wrapper: styles,
9
- })) )
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type TooltipSide = 'left' | 'right' | 'bottom' | 'top'
4
+ export type TooltipState = 'delayed-open' | 'closed' | 'instant-open' | 'disabled'
5
+ export type TooltipParts = 'wrapper' | 'arrow'
6
+
7
+ export type TooltipComposition = `wrapper:${TooltipSide}` | TooltipParts
8
+
9
+ const createTooltipStyle = createDefaultVariantFactory<TooltipComposition>()
10
+
11
+ export const TooltipPresets = includePresets((styles) => createTooltipStyle(() => ({
12
+ wrapper: styles,
13
+ })))
@@ -1,67 +1,129 @@
1
- /** @jsx jsx */
2
- import { CSSObject, jsx } from '@emotion/react'
3
- import { AnyFunction, useCodeleapContext } from '@codeleap/common'
4
- import React, { forwardRef } from 'react'
1
+ import { AnyFunction, ComponentVariants, onMount, TypeGuards, useCodeleapContext, useDefaultComponentStyle } from '@codeleap/common'
2
+ import React, { ComponentPropsWithRef, ElementType, forwardRef } from 'react'
5
3
  import { stopPropagation } from '../../lib'
6
4
  import { View } from '../View'
7
- import { TouchableComposition } from './styles'
8
- import { StylesOf, NativeHTMLElement, HTMLProps } from '../../types'
5
+ import { TouchableComposition, TouchablePresets } from './styles'
6
+ import { CSSInterpolation } from '@emotion/css'
7
+ import { StylesOf, NativeHTMLElement } from '../../types'
9
8
 
10
9
  export * from './styles'
11
10
 
12
- export type TouchableProps<T extends NativeHTMLElement = 'button'> = Omit<HTMLProps<T>, 'style'> & {
11
+ export type TouchableProps<T extends ElementType = 'button'> = ComponentPropsWithRef<T> & {
12
+ css?: CSSInterpolation | CSSInterpolation[]
13
13
  component?: T
14
14
  disabled?: boolean
15
15
  propagate?: boolean
16
- style?: CSSObject
16
+ style?: React.CSSObject
17
17
  onPress?: AnyFunction
18
+ debugName: string
18
19
  debugComponent?: string
19
- debugName?: string
20
20
  styles?: StylesOf<TouchableComposition>
21
- }
21
+ debounce?: number
22
+ leadingDebounce?: boolean
23
+ setPressed?: (pressed: boolean) => void
24
+ } & ComponentVariants<typeof TouchablePresets>
22
25
 
23
26
  export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
24
27
  touchableProps: TouchableProps<T>,
25
28
  ref,
26
29
  ) => {
27
30
  const {
28
-
29
31
  propagate = true,
32
+ debounce = null,
33
+ leadingDebounce,
34
+ setPressed,
30
35
  component: Component = View,
31
36
  disabled,
32
37
  onPress,
33
38
  onClick,
34
- debugComponent,
35
39
  debugName,
40
+ debugComponent,
41
+ style = {},
42
+ styles = {},
43
+ responsiveVariants = {},
44
+ variants = [],
45
+ css = [],
36
46
  ...props
37
- } = touchableProps
47
+ } = touchableProps as TouchableProps
48
+
49
+ const pressed = React.useRef(!!leadingDebounce)
50
+
51
+ onMount(() => {
52
+ if (!!leadingDebounce && !!debounce) {
53
+ setTimeout(() => {
54
+ pressed.current = false
55
+ }, debounce)
56
+ }
57
+ })
58
+
59
+ const variantStyles = useDefaultComponentStyle<'u:Touchable', typeof TouchablePresets>('u:Touchable', {
60
+ responsiveVariants,
61
+ variants,
62
+ styles,
63
+ rootElement: 'wrapper'
64
+ })
38
65
 
39
66
  const { logger } = useCodeleapContext()
40
67
 
41
- const handleClick = (event: React.MouseEvent<T>) => {
68
+ const notPressable = !TypeGuards.isFunction(onPress) && !TypeGuards.isFunction(onClick)
69
+
70
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
42
71
  if (disabled) return
43
72
 
44
73
  if (!propagate) stopPropagation(event)
45
74
 
46
- if (!onPress && !onClick) {
47
- logger.warn('No onPress passed to touchable', touchableProps)
75
+ if (notPressable) {
76
+ logger.warn(
77
+ 'No onPress passed to touchable',
78
+ touchableProps,
79
+ 'User interaction'
80
+ )
48
81
  return
49
82
  }
50
83
 
51
- logger.log(
52
- `<${debugComponent || 'Touchable'}/> pressed`,
53
- { debugName, debugComponent },
54
- 'User interaction',
55
- )
56
- // @ts-ignore
57
- onClick?.(event)
58
- onPress && onPress()
84
+ const _onPress = () => {
85
+ logger.log(
86
+ `<${debugComponent || 'Touchable'}/> pressed`,
87
+ { debugName, debugComponent },
88
+ 'User interaction'
89
+ )
90
+
91
+ if (TypeGuards.isFunction(onClick)) onClick?.(event)
92
+ onPress?.()
93
+ }
59
94
 
95
+ if (TypeGuards.isNumber(debounce)) {
96
+ if (pressed.current) {
97
+ return
98
+ }
99
+ setPressed?.(true)
100
+ pressed.current = true
101
+ _onPress()
102
+ setTimeout(() => {
103
+ setPressed?.(false)
104
+ pressed.current = false
105
+ }, debounce)
106
+ } else {
107
+ _onPress()
108
+ }
60
109
  }
61
110
 
111
+ const _styles = React.useMemo(() => ([
112
+ variantStyles.wrapper,
113
+ disabled && variantStyles['wrapper:disabled'],
114
+ css,
115
+ style,
116
+ ]), [variantStyles, disabled])
117
+
62
118
  return (
63
- // @ts-ignore
64
- <View component={Component || 'button'} {...props} debugName={debugName} onClick={handleClick} ref={ref}/>
119
+ <View
120
+ component={Component || 'button'}
121
+ {...props}
122
+ debugName={debugName}
123
+ onClick={handleClick}
124
+ ref={ref}
125
+ css={_styles}
126
+ />
65
127
  )
66
128
  }
67
129
 
@@ -1,11 +1,9 @@
1
1
  import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
- import { StylesOf } from '../../types'
3
2
 
4
- export type TouchableComposition = 'wrapper'
3
+ export type TouchableState = 'disabled'
4
+ export type TouchableParts = 'wrapper'
5
+ export type TouchableComposition = TouchableParts | `${TouchableParts}:${TouchableState}`
5
6
 
6
- const createTouchableStyle = createDefaultVariantFactory<
7
- TouchableComposition
8
- >()
7
+ const createTouchableStyle = createDefaultVariantFactory<TouchableComposition>()
9
8
 
10
9
  export const TouchablePresets = includePresets((styles) => createTouchableStyle(() => ({ wrapper: styles })))
11
-
@@ -90,7 +90,7 @@ export const ViewCP = (
90
90
  style,
91
91
  css,
92
92
  ]
93
- }, [scroll, matches, css])
93
+ }, [variantStyles, scroll, matches, css])
94
94
 
95
95
  const onHoverProps = TypeGuards.isFunction(onHover) && {
96
96
  onMouseEnter: () => handleHover(true),
@@ -18,12 +18,16 @@ export * from './RadioInput'
18
18
  export * from './Select'
19
19
  export * from './FileInput'
20
20
  export * from './Slider'
21
- export * from './Tooltip'
22
21
  export * from './List'
23
22
  export * from './LoadingOverlay'
24
23
  export * from './InputBase'
25
24
  export * from './Switch'
26
25
  export * from './NumberIncrement'
26
+ export * from './SearchInput'
27
+ export * from './Tooltip'
27
28
  export * from './SegmentedControl'
28
29
  export * from './Pager'
30
+ export * from './EmptyPlaceholder'
31
+ export * from './Grid'
32
+ export * from './Badge'
29
33
  export * from './defaultStyles'
@@ -14,15 +14,18 @@ import { OverlayPresets } from './Overlay/styles'
14
14
  import { TextInputPresets } from './TextInput/styles'
15
15
  import { RadioInputPresets } from './RadioInput/styles'
16
16
  import { SelectPresets } from './Select/styles'
17
- import { TooltipPresets } from './Tooltip/styles'
18
- import { ListPresets } from './List/styles'
17
+ import { ListPresets, PaginationIndicatorStyles } from './List'
19
18
  import { SliderPresets } from './Slider/styles'
20
19
  import { LoadingOverlayPresets } from './LoadingOverlay/styles'
21
20
  import { InputBasePresets } from './InputBase'
22
21
  import { SwitchPresets } from './Switch/styles'
23
22
  import { NumberIncrementPresets } from './NumberIncrement/styles'
23
+ import { TooltipPresets } from './Tooltip/styles'
24
24
  import { SegmentedControlPresets } from './SegmentedControl/styles'
25
25
  import { PagerPresets } from './Pager/styles'
26
+ import { EmptyPlaceholderPresets } from './EmptyPlaceholder/styles'
27
+ import { GridPresets } from './Grid/styles'
28
+ import { BadgePresets } from './Badge/styles'
26
29
 
27
30
  export const defaultStyles = {
28
31
  View: ViewPresets,
@@ -42,15 +45,19 @@ export const defaultStyles = {
42
45
  TextInput: TextInputPresets,
43
46
  RadioInput: RadioInputPresets,
44
47
  Select: SelectPresets,
45
- Tooltip: TooltipPresets,
46
48
  List: ListPresets,
47
49
  Slider: SliderPresets,
48
50
  LoadingOverlay: LoadingOverlayPresets,
49
51
  InputBase: InputBasePresets,
50
52
  Switch: SwitchPresets,
51
53
  NumberIncrement: NumberIncrementPresets,
54
+ Tooltip: TooltipPresets,
52
55
  SegmentedControlPresets: SegmentedControlPresets,
53
56
  Pager: PagerPresets,
57
+ EmptyPlaceholder: EmptyPlaceholderPresets,
58
+ PaginationIndicator: PaginationIndicatorStyles,
59
+ Grid: GridPresets,
60
+ Badge: BadgePresets,
54
61
  }
55
62
 
56
63
  import createCache from '@emotion/cache'
package/src/index.ts CHANGED
@@ -2,5 +2,7 @@ export * from './components/components'
2
2
  export * from './lib/hooks'
3
3
  export * from './lib/utils'
4
4
  export * from './types/utility'
5
+ export * from './lib/useSearchParams'
6
+ export * from './lib/useBreakpointMatch'
5
7
  export { default as Toast } from './lib/Toast'
6
8
  export { CreateOSAlert } from './lib/OSAlert'
package/src/lib/hooks.ts CHANGED
@@ -236,7 +236,8 @@ export function usePagination({
236
236
 
237
237
 
238
238
  export interface UseMediaQueryOptions {
239
- getInitialValueInEffect: boolean;
239
+ getInitialValueInEffect?: boolean
240
+ initialValue?: boolean
240
241
  }
241
242
 
242
243
  type MediaQueryCallback = (event: { matches: boolean; media: string }) => void;
@@ -245,7 +246,7 @@ type MediaQueryCallback = (event: { matches: boolean; media: string }) => void;
245
246
  * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia
246
247
  * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent
247
248
  * */
248
- function attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {
249
+ export function attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {
249
250
  try {
250
251
  query.addEventListener('change', callback);
251
252
  return () => query.removeEventListener('change', callback);
@@ -267,35 +268,48 @@ function getInitialValue(query: string, initialValue?: boolean) {
267
268
  return false;
268
269
  }
269
270
 
271
+ export function isMediaQuery(query: string, initialValue = false) {
272
+ const media = query.trim().replace('@media screen and ', '')
273
+
274
+ if (typeof window !== 'undefined' && 'matchMedia' in window) {
275
+ return window.matchMedia(media).matches
276
+ }
277
+
278
+ return initialValue
279
+ }
280
+
270
281
  export function useMediaQuery(
271
282
  query: string,
272
- initialValue?: boolean,
273
- { getInitialValueInEffect }: UseMediaQueryOptions = {
274
- getInitialValueInEffect: true,
275
- }
283
+ queryOptions: UseMediaQueryOptions = {}
276
284
  ) {
285
+ const {
286
+ initialValue = false,
287
+ getInitialValueInEffect = true,
288
+ } = queryOptions
277
289
 
278
290
  const _query = useMemo(() => {
279
291
  return query.trim().replace('@media screen and ', '')
280
-
281
292
  }, [query])
293
+
282
294
  const [matches, setMatches] = useState(
283
- getInitialValueInEffect ? initialValue : getInitialValue(_query, initialValue)
284
- );
285
- const queryRef = useRef<MediaQueryList>();
295
+ getInitialValueInEffect ? initialValue : isMediaQuery(query, initialValue)
296
+ )
297
+
298
+ const queryRef = useRef<MediaQueryList>()
286
299
 
287
300
  useEffect(() => {
288
301
  if(query.trim() === '') return
302
+
289
303
  if ('matchMedia' in window) {
290
304
  queryRef.current = window.matchMedia(_query);
291
305
  setMatches(queryRef.current.matches);
292
306
  return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
293
307
  }
294
308
 
295
- return undefined;
296
- }, [_query]);
309
+ return undefined
310
+ }, [_query])
297
311
 
298
- return matches;
312
+ return matches
299
313
  }
300
314
 
301
315
  type SelectProperties<T extends Record<string|number|symbol, any>, K extends keyof T> = {