@codeleap/web 3.18.8 → 3.19.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.18.8",
3
+ "version": "3.19.0",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -25,6 +25,7 @@ import { StylesOf, HTMLProps, ComponentWithDefaultProps } from '../../types/util
25
25
  import { InputBase, InputBaseProps, selectInputBaseProps } from '../InputBase'
26
26
  import { TextInputPresets } from './styles'
27
27
  import { getMaskInputProps, TextInputMaskingProps } from './mask'
28
+ import { getTestId } from '../../lib/test'
28
29
 
29
30
  export * from './styles'
30
31
  export * from './mask'
@@ -53,8 +54,8 @@ export type TextInputProps =
53
54
  } & ComponentVariants<typeof TextInputPresets>
54
55
 
55
56
  type InputRef = {
56
- isTextInput?: boolean,
57
- focus: () => void,
57
+ isTextInput?: boolean
58
+ focus: () => void
58
59
  getInputRef: () => HTMLInputElement
59
60
  }
60
61
 
@@ -201,6 +202,8 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
201
202
 
202
203
  const inputBaseAction = isPressable ? 'onPress' : 'onClick'
203
204
 
205
+ const testId = getTestId(others)
206
+
204
207
  return (
205
208
  <InputBase
206
209
  innerWrapper={isPressable ? Touchable : undefined}
@@ -262,6 +265,7 @@ export const TextInputComponent = forwardRef<InputRef, TextInputProps>((props, i
262
265
  ]}
263
266
  {...maskProps}
264
267
  ref={innerInputRef}
268
+ data-testid={testId}
265
269
  />
266
270
  </InputBase>
267
271
  )
@@ -47,6 +47,7 @@ export type TooltipProps = PrimitiveTooltipProps & TooltipComponentProps & {
47
47
  onHover?: (hoverType: 'enter' | 'leave', value: boolean) => void
48
48
  onPress?: (value: boolean) => void
49
49
  children?: React.ReactNode
50
+ style?: React.CSSProperties
50
51
  } & ComponentVariants<typeof TooltipPresets> & ComponentCommonProps
51
52
 
52
53
  const defaultProps: Partial<TooltipProps> = {
@@ -91,6 +92,7 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
91
92
  responsiveVariants = {},
92
93
  styles = {},
93
94
  closeOnClickOutside,
95
+ style,
94
96
  ...rest
95
97
  } = allProps
96
98
 
@@ -105,7 +107,7 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
105
107
  const [visible, toggle] = hasStateProps ? [_visible, _toggle] : useState(false)
106
108
 
107
109
  const tooltipDirectionStyle = React.useMemo(() => {
108
- return side ? variantsStyles[`wrapper:${side}`] : variantsStyles.wrapper
110
+ return side ? variantsStyles[`content:${side}`] : variantsStyles.content
109
111
  }, [side, variantsStyles])
110
112
 
111
113
  function handleToggle(_value: boolean, isToggle = true) {
@@ -161,6 +163,7 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
161
163
  open={visible}
162
164
  onOpenChange={onOpenChange}
163
165
  {...rest}
166
+ css={[variantsStyles.wrapper, style]}
164
167
  >
165
168
  <TooltipTrigger
166
169
  onClick={_onPress}
@@ -169,13 +172,18 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
169
172
  asChild
170
173
  ref={triggerRef}
171
174
  {...triggerProps}
175
+ style={variantsStyles.triggerWrapper}
172
176
  >
173
- <TriggerWrapper {...allProps as any} {...triggerWrapperProps}>
177
+ <TriggerWrapper
178
+ {...allProps as any}
179
+ {...triggerWrapperProps}
180
+ style={variantsStyles.triggerInnerWrapper}
181
+ >
174
182
  {children}
175
183
  </TriggerWrapper>
176
184
  </TooltipTrigger>
177
185
  <TooltipPortal {...portalProps}>
178
- <TooltipContent ref={contentRef} css={[tooltipDirectionStyle, variantsStyles.wrapper]} sideOffset={2} side={side} {...contentProps}>
186
+ <TooltipContent ref={contentRef} css={[tooltipDirectionStyle, variantsStyles.content]} sideOffset={2} side={side} {...contentProps}>
179
187
  {
180
188
  TypeGuards.isFunction(Content)
181
189
  ? <Content
@@ -186,7 +194,7 @@ export const Tooltip: ComponentWithDefaultProps<TooltipProps> = (props: TooltipP
186
194
  />
187
195
  : Content
188
196
  }
189
- <TooltipArrow {...arrowProps} />
197
+ <TooltipArrow {...arrowProps} style={variantsStyles.arrow} />
190
198
  </TooltipContent>
191
199
  </TooltipPortal>
192
200
  </TooltipWrapper>
@@ -2,9 +2,14 @@ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
2
 
3
3
  export type TooltipSide = 'left' | 'right' | 'bottom' | 'top'
4
4
  export type TooltipState = 'delayed-open' | 'closed' | 'instant-open' | 'disabled'
5
- export type TooltipParts = 'wrapper' | 'arrow'
5
+ export type TooltipParts =
6
+ 'wrapper' |
7
+ 'arrow' |
8
+ 'content' |
9
+ 'triggerWrapper' |
10
+ 'triggerInnerWrapper'
6
11
 
7
- export type TooltipComposition = `wrapper:${TooltipSide}` | TooltipParts
12
+ export type TooltipComposition = `content:${TooltipSide}` | TooltipParts
8
13
 
9
14
  const createTooltipStyle = createDefaultVariantFactory<TooltipComposition>()
10
15
 
@@ -5,7 +5,7 @@ import { View } from '../View'
5
5
  import { TouchableComposition, TouchablePresets } from './styles'
6
6
  import { CSSInterpolation } from '@emotion/css'
7
7
  import { StylesOf, NativeHTMLElement } from '../../types'
8
-
8
+ import { getTestId } from '../../lib/test'
9
9
  export * from './styles'
10
10
 
11
11
  export type TouchableProps<T extends ElementType = 'button'> = ComponentPropsWithRef<T> & {
@@ -147,6 +147,8 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
147
147
  style,
148
148
  ]), [variantStyles, disabled, style])
149
149
 
150
+ const testId = getTestId(mergedProps)
151
+
150
152
  return (
151
153
  <View
152
154
  component={Component || 'button'}
@@ -156,6 +158,7 @@ export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
156
158
  onKeyDown={handleClick}
157
159
  ref={ref}
158
160
  css={_styles}
161
+ data-testid={testId}
159
162
  />
160
163
  )
161
164
  }
@@ -7,6 +7,7 @@ import { useMediaQuery } from '../../lib/hooks'
7
7
  import { NativeHTMLElement } from '../../types'
8
8
  import { motion } from 'framer-motion'
9
9
  import { ViewProps } from './types'
10
+ import { getTestId } from '../../lib/test'
10
11
 
11
12
  export * from './styles'
12
13
  export * from './types'
@@ -80,6 +81,8 @@ export const ViewCP = (
80
81
  logger.log(debugName, { componentStyles, platformMediaQuery, matches })
81
82
  }
82
83
 
84
+ const testId = getTestId(viewProps)
85
+
83
86
  return (
84
87
  <Component
85
88
  css={componentStyles}
@@ -87,6 +90,7 @@ export const ViewCP = (
87
90
  {...onHoverProps}
88
91
  {...props}
89
92
  {...animatedProps}
93
+ data-testid={testId}
90
94
  >
91
95
  {children}
92
96
  </Component>
@@ -0,0 +1,11 @@
1
+ import { TypeGuards } from '@codeleap/common'
2
+
3
+ export const getTestId = (props: Record<string, any>) => {
4
+ let id = props.testId || props['data-testid'] || props.id || props.debugName
5
+
6
+ if (TypeGuards.isString(id)) {
7
+ id = id.replace(/\s/g, '_').toLowerCase()
8
+ }
9
+
10
+ return id
11
+ }
@@ -2,3 +2,4 @@ export * from './pollyfils/scroll'
2
2
  export * from './stopPropagation'
3
3
  export { default as url } from 'url-parse'
4
4
  export { default as Cookies } from './cookies'
5
+