Skip to content

Commit f4d2522

Browse files
committed
fix: more improvements
1 parent 7cb08d1 commit f4d2522

File tree

41 files changed

+547
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+547
-498
lines changed

packages/form/src/components/CheckboxGroupField/__tests__/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('checkboxField', () => {
6464
expect(input).toBeChecked()
6565

6666
await userEvent.click(input)
67-
expect(onChange).toBeCalledTimes(2)
67+
expect(onChange).toHaveBeenCalledTimes(2)
6868
expect(input).not.toBeChecked()
6969

7070
expect(asFragment()).toMatchSnapshot()

packages/form/src/components/DateInputField/__tests__/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('dateInputField', () => {
7373
await userEvent.click(screen.getByText('15'))
7474

7575
await waitFor(() => {
76-
expect(onChange).toBeCalledTimes(2)
76+
expect(onChange).toHaveBeenCalledTimes(2)
7777
})
7878

7979
expect(resultForm.current.getValues('test')).toEqual([

packages/form/src/components/SelectableCardGroupField/__tests__/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('selectableCardField', () => {
8383
await userEvent.click(input)
8484
expect(onChange).toHaveBeenCalledOnce()
8585
await userEvent.click(input)
86-
expect(onChange).toBeCalledTimes(2)
86+
expect(onChange).toHaveBeenCalledTimes(2)
8787
expect(asFragment()).toMatchSnapshot()
8888
})
8989
})

packages/form/src/components/ToggleGroupField/__tests__/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('groupField', () => {
6969
expect(input).toBeChecked()
7070

7171
await userEvent.click(input)
72-
expect(onChange).toBeCalledTimes(2)
72+
expect(onChange).toHaveBeenCalledTimes(2)
7373
expect(input).not.toBeChecked()
7474
expect(asFragment()).toMatchSnapshot()
7575
})

packages/plus/src/components/OfferList/__tests__/index.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ describe('offerList', () => {
207207
<OfferList.Cell>a cell</OfferList.Cell>
208208
</OfferList.Row>,
209209
),
210-
).toThrowError(
211-
'useOfferListContext should be used inside a OfferList component',
212-
)
210+
).toThrow('useOfferListContext should be used inside a OfferList component')
213211
})
214212
})

packages/ui/src/components/BarStack/__tests__/index.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ describe('barStack', () => {
8484
expect(onMouseEnter).toHaveBeenCalledOnce()
8585
expect(onMouseDown).toHaveBeenCalledOnce()
8686
expect(onMouseUp).toHaveBeenCalledOnce()
87-
expect(onDoubleClick).toBeCalledTimes(0)
88-
expect(onMouseLeave).toBeCalledTimes(0)
87+
expect(onDoubleClick).toHaveBeenCalledTimes(0)
88+
expect(onMouseLeave).toHaveBeenCalledTimes(0)
8989
await userEvent.dblClick(helloDiv)
9090
expect(onDoubleClick).toHaveBeenCalledOnce()
91-
expect(onClick).toBeCalledTimes(3)
91+
expect(onClick).toHaveBeenCalledTimes(3)
9292
await userEvent.unhover(helloDiv)
9393
expect(onMouseLeave).toHaveBeenCalledOnce()
9494

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { assignInlineVars } from '@vanilla-extract/dynamic'
2+
3+
import { carouselStyle, widthVar } from './styles.css'
4+
5+
import type { CSSProperties, ReactNode } from 'react'
6+
7+
type CarouselItemProps = {
8+
children: ReactNode
9+
width?: string
10+
style?: CSSProperties
11+
}
12+
export const CarouselItem = ({
13+
children,
14+
width = '240px',
15+
style,
16+
}: CarouselItemProps) => (
17+
<div
18+
className={carouselStyle.borderWrapper}
19+
draggable="true"
20+
style={{
21+
...assignInlineVars({
22+
[widthVar]: width,
23+
}),
24+
...style,
25+
}}
26+
>
27+
{children}
28+
</div>
29+
)

packages/ui/src/components/Carousel/index.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
'use client'
22

33
import { cn } from '@ultraviolet/utils'
4-
import { assignInlineVars } from '@vanilla-extract/dynamic'
54
import { useEffect, useRef, useState } from 'react'
65

7-
import { carouselStyle, widthVar } from './styles.css'
6+
import { CarouselItem } from './Item'
7+
import { carouselStyle } from './styles.css'
88

9-
import type { CSSProperties, ReactNode } from 'react'
10-
11-
type CarouselItemProps = {
12-
children: ReactNode
13-
width?: string
14-
style?: CSSProperties
15-
}
16-
export const CarouselItem = ({
17-
children,
18-
width = '240px',
19-
style,
20-
}: CarouselItemProps) => (
21-
<div
22-
className={carouselStyle.borderWrapper}
23-
draggable="true"
24-
style={{
25-
...assignInlineVars({
26-
[widthVar]: width,
27-
}),
28-
...style,
29-
}}
30-
>
31-
{children}
32-
</div>
33-
)
9+
import type { ReactNode } from 'react'
3410

3511
type CarouselProps = {
3612
className?: string
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use client'
2+
3+
import { createContext } from 'react'
4+
5+
import type { InputHTMLAttributes } from 'react'
6+
7+
type CheckboxGroupContextType = {
8+
groupName: string
9+
groupValues: string[]
10+
error: boolean
11+
} & Required<Pick<InputHTMLAttributes<HTMLInputElement>, 'onChange'>> &
12+
Pick<InputHTMLAttributes<HTMLInputElement>, 'required'>
13+
14+
export const CheckboxGroupContext = createContext<
15+
CheckboxGroupContextType | undefined
16+
>(undefined)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use client'
2+
3+
import { cn } from '@ultraviolet/utils'
4+
import { useContext } from 'react'
5+
6+
import { Checkbox } from '../Checkbox'
7+
8+
import { CheckboxGroupContext } from './Context'
9+
import { checkboxGroupStyle } from './styles.css'
10+
11+
import type { ComponentProps } from 'react'
12+
13+
type CheckboxGroupCheckboxProps = Omit<
14+
ComponentProps<typeof Checkbox>,
15+
'onChange' | 'checked'
16+
> & {
17+
value: string
18+
}
19+
20+
export const CheckboxGroupCheckbox = ({
21+
onFocus,
22+
onBlur,
23+
disabled,
24+
error,
25+
name,
26+
value,
27+
children,
28+
helper,
29+
className,
30+
autoFocus,
31+
'data-testid': dataTestId,
32+
required,
33+
tooltip,
34+
style,
35+
size,
36+
}: CheckboxGroupCheckboxProps) => {
37+
const context = useContext(CheckboxGroupContext)
38+
39+
if (!context) {
40+
throw new Error(
41+
'CheckboxGroup.Checkbox can only be used inside a CheckboxGroup',
42+
)
43+
}
44+
45+
const { groupName, onChange, groupValues, error: errorContext } = context
46+
47+
const checkboxName = `${groupName}.${name ?? ''}`
48+
const checkboxValue = value.toString()
49+
50+
return (
51+
<Checkbox
52+
autoFocus={autoFocus} // oxlint-disable-line jsx_a11y/no-autofocus
53+
checked={groupValues?.includes(checkboxValue)}
54+
className={cn(className, checkboxGroupStyle.checkboxGroup)}
55+
data-testid={dataTestId}
56+
disabled={disabled}
57+
error={error || errorContext}
58+
helper={helper}
59+
name={checkboxName}
60+
onBlur={onBlur}
61+
onChange={onChange}
62+
onFocus={onFocus}
63+
required={required}
64+
size={size}
65+
style={style}
66+
tooltip={tooltip}
67+
value={checkboxValue}
68+
>
69+
{children}
70+
</Checkbox>
71+
)
72+
}

0 commit comments

Comments
 (0)