Skip to content

Commit e5a4ab3

Browse files
committed
feat(*): make useListCollection more flexible
1 parent 608927e commit e5a4ab3

File tree

8 files changed

+31
-15
lines changed

8 files changed

+31
-15
lines changed

packages/react/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- Added `Carousel.AutoplayIndicator` component for conditionally rendering content based on autoplay state
77
- Added `Carousel.ProgressText` component for displaying current page progress (e.g., "1 / 5")
88

9+
### Changed
10+
11+
- **useListCollection**: Updated `initialItems` to accept `readonly` arrays for better compatibility with immutable data patterns.
12+
913
### Fixed
1014

1115
- **Combobox**:

packages/react/src/components/collection/use-list-collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface UseListCollectionProps<T> extends Omit<CollectionOptions<T>, 'i
66
/**
77
* The initial items to display in the collection.
88
*/
9-
initialItems: T[]
9+
initialItems: T[] | readonly T[]
1010
/**
1111
* The filter function to use to filter the items.
1212
*/
@@ -24,15 +24,15 @@ export function useListCollection<T>(props: UseListCollectionProps<T>): UseListC
2424
const [items, setItemsImpl] = useState(initialItems)
2525
const [filterText, setFilterText] = useState<string>('')
2626

27-
const setItems = useEvent((items: T[]) => {
27+
const setItems = useEvent((items: T[] | readonly T[]) => {
2828
setItemsImpl(items)
2929
setFilterText('')
3030
})
3131

3232
const collectionOptionsRef = useRef(collectionOptions)
3333
collectionOptionsRef.current = collectionOptions
3434

35-
const create = useCallback((items: T[]) => {
35+
const create = useCallback((items: T[] | readonly T[]) => {
3636
return createListCollection({ ...collectionOptionsRef.current, items })
3737
}, [])
3838

packages/solid/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- Added `Carousel.AutoplayIndicator` component for conditionally rendering content based on autoplay state
77
- Added `Carousel.ProgressText` component for displaying current page progress (e.g., "1 / 5")
88

9+
### Changed
10+
11+
- **useListCollection**: Updated `initialItems` to accept `readonly` arrays for better compatibility with immutable data patterns.
12+
913
### Fixed
1014

1115
- **Combobox**:

packages/solid/src/components/collection/use-list-collection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface UseListCollectionProps<T> extends Omit<CollectionOptions<T>, 'i
66
/**
77
* The initial items to display in the collection.
88
*/
9-
initialItems: T[]
9+
initialItems: T[] | readonly T[]
1010
/**
1111
* The filter function to use to filter the items.
1212
*/
@@ -29,15 +29,15 @@ export function useListCollection<T>(props: MaybeAccessor<UseListCollectionProps
2929
return localProps.initialItems
3030
}
3131

32-
const [items, setItemsImpl] = createSignal<T[]>(init())
32+
const [items, setItemsImpl] = createSignal<T[] | readonly T[]>(init())
3333
const [filterText, setFilterText] = createSignal('')
3434

35-
const setItems = (newItems: T[]) => {
35+
const setItems = (newItems: T[] | readonly T[]) => {
3636
setItemsImpl(newItems)
3737
setFilterText('')
3838
}
3939

40-
const create = (itemsToCreate: T[]) => {
40+
const create = (itemsToCreate: T[] | readonly T[]) => {
4141
const [, collectionOptions] = splittedProps()
4242
return createListCollection({ ...collectionOptions, items: itemsToCreate })
4343
}

packages/svelte/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ description: All notable changes will be documented in this file.
1212
- Added `Carousel.AutoplayIndicator` component for conditionally rendering content based on autoplay state
1313
- Added `Carousel.ProgressText` component for displaying current page progress (e.g., "1 / 5")
1414

15+
### Changed
16+
17+
- **useListCollection**: Updated `initialItems` to accept `readonly` arrays for better compatibility with immutable data patterns.
18+
1519
### Fixed
1620

1721
- **Slider**: Fixed `Slider.ValueText` not displaying default value when no children provided

packages/svelte/src/lib/components/collection/use-list-collection.svelte.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface UseListCollectionProps<T> extends Omit<CollectionOptions<T>, 'i
66
/**
77
* The initial items to display in the collection.
88
*/
9-
initialItems: T[]
9+
initialItems: T[] | readonly T[]
1010
/**
1111
* The filter function to use to filter the items.
1212
*/
@@ -24,15 +24,15 @@ export function useListCollection<T>(props: MaybeFunction<UseListCollectionProps
2424
return [{ initialItems, filter, limit }, collectionOptions]
2525
})
2626

27-
let items = $state<T[]>(untrack(() => localProps.initialItems))
27+
let items = $state<T[] | readonly T[]>(untrack(() => localProps.initialItems))
2828
let filterText = $state('')
2929

30-
const setItems = (newItems: T[]) => {
30+
const setItems = (newItems: T[] | readonly T[]) => {
3131
items = newItems
3232
filterText = ''
3333
}
3434

35-
const create = (itemsToCreate: T[]) => {
35+
const create = (itemsToCreate: T[] | readonly T[]) => {
3636
return createListCollection({ ...collectionOptions, items: itemsToCreate })
3737
}
3838

packages/vue/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- Added `Carousel.AutoplayIndicator` component for conditionally rendering content based on autoplay state
77
- Added `Carousel.ProgressText` component for displaying current page progress (e.g., "1 / 5")
88

9+
### Changed
10+
11+
- **useListCollection**: Updated `initialItems` to accept `readonly` arrays for better compatibility with immutable data patterns.
12+
913
### Fixed
1014

1115
- **Combobox**:

packages/vue/src/components/collection/use-list-collection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface UseListCollectionProps<T> extends Omit<CollectionOptions<T>, 'i
55
/**
66
* The initial items to display in the collection.
77
*/
8-
initialItems: T[]
8+
initialItems: T[] | readonly T[]
99
/**
1010
* The filter function to use to filter the items.
1111
*/
@@ -28,15 +28,15 @@ export function useListCollection<T>(props: MaybeRef<UseListCollectionProps<T>>)
2828
return initialItems
2929
}
3030

31-
const items = ref(init()) as Ref<T[]>
31+
const items = ref(init()) as Ref<T[] | readonly T[]>
3232
const filterText = ref('')
3333

34-
const setItems = (newItems: T[]) => {
34+
const setItems = (newItems: T[] | readonly T[]) => {
3535
items.value = newItems
3636
filterText.value = ''
3737
}
3838

39-
const create = (itemsToCreate: T[]) => {
39+
const create = (itemsToCreate: T[] | readonly T[]) => {
4040
const [, collectionOptions] = resolvedProps.value
4141
return createListCollection({ ...collectionOptions, items: itemsToCreate })
4242
}

0 commit comments

Comments
 (0)