diff --git a/apps/docs/pages/docs/v2/Components/Lists/sectionlist.en-US.mdx b/apps/docs/pages/docs/v2/Components/Lists/sectionlist.en-US.mdx new file mode 100644 index 00000000..1885bf13 --- /dev/null +++ b/apps/docs/pages/docs/v2/Components/Lists/sectionlist.en-US.mdx @@ -0,0 +1,51 @@ +--- +searchable: true +--- + +import { CodeEditor } from '@components/code-editor'; + +# SectionList + +Wrapper around `SectionList` component from `react-native`, it accepts every props from react native `SectionList` component. + +## Import + +```js +import { SectionList } from "@ficus-ui/native"; +``` + +## Usage + + item + index} + renderItem={({ item }) => ( + + {item} + + )} + renderSectionHeader={({ section: { title } }) => ( + + {title} + + )} +/>`} /> + +## Props + +Extends every `Box` props and props from react native `SectionList` component : https://reactnative.dev/docs/sectionlist#props diff --git a/apps/examples/app/components-v2/SectionList.tsx b/apps/examples/app/components-v2/SectionList.tsx new file mode 100644 index 00000000..613d87b6 --- /dev/null +++ b/apps/examples/app/components-v2/SectionList.tsx @@ -0,0 +1,46 @@ +import { Box, Flex, SafeAreaBox, SectionList, Text } from '@ficus-ui/native'; + + +const SectionListComponent = () => { + const DATA = [ + { + title: "Main dishes", + data: ["Pizza", "Burger", "Risotto"], + }, + { + title: "Sides", + data: ["French Fries", "Onion Rings", "Fried Shrimps"], + }, + { + title: "Drinks", + data: ["Water", "Coke", "Beer"], + }, + ] + return ( + + + SectionList component + + + `${item.title}-${index}`} + renderItem={({ item }:any) => ( + + {item} + + )} + renderSectionHeader={({ section: { title } }:any) => ( + + {title} + + )} + /> + + + ); +}; + +export default SectionListComponent; diff --git a/apps/examples/app/items-v2.ts b/apps/examples/app/items-v2.ts index d5e2598b..407895b9 100644 --- a/apps/examples/app/items-v2.ts +++ b/apps/examples/app/items-v2.ts @@ -17,6 +17,7 @@ import SpinnerComponent from '@/app/components-v2/Spinner'; import SliderComponent from '@/app/components-v2/Slider'; import IconComponent from '@/app/components-v2/Icon'; import ListComponent from '@/app/components-v2/List'; +import SectionListComponent from '@/app/components-v2/SectionList'; type ExampleComponentType = { onScreenName: string; @@ -43,4 +44,5 @@ export const components: ExampleComponentType[] = [ { navigationPath: 'Slider', onScreenName: 'Slider', component: SliderComponent }, { navigationPath: 'Icon', onScreenName: 'Icon', component: IconComponent }, { navigationPath: 'List', onScreenName: 'List', component: ListComponent }, + { navigationPath: 'SectionList', onScreenName: 'SectionList', component: SectionListComponent }, ]; diff --git a/packages/components/src/index.ts b/packages/components/src/index.ts index c372b181..4e240a8a 100644 --- a/packages/components/src/index.ts +++ b/packages/components/src/index.ts @@ -14,5 +14,6 @@ export * from './spinner'; export * from './slider'; export * from './icon'; export * from './list'; +export * from './section-list'; export { ThemeProvider } from '@ficus-ui/theme'; diff --git a/packages/components/src/section-list/index.tsx b/packages/components/src/section-list/index.tsx new file mode 100644 index 00000000..dc0d300f --- /dev/null +++ b/packages/components/src/section-list/index.tsx @@ -0,0 +1,5 @@ +import { type NativeFicusProps, ficus } from '../system'; + +export interface SectionListProps extends NativeFicusProps<'SectionList'> {} + +export const SectionList = ficus('SectionList'); diff --git a/packages/components/src/section-list/section-list.spec.tsx b/packages/components/src/section-list/section-list.spec.tsx new file mode 100644 index 00000000..0db1f214 --- /dev/null +++ b/packages/components/src/section-list/section-list.spec.tsx @@ -0,0 +1,59 @@ +import React from 'react'; + +import { render } from '@testing-library/react-native'; + +import { SectionList } from '.'; +import { Box } from '../box'; +import { Text } from '../text'; + +const MySectionList = ({ sections }: any) => { + return ( + (item.title + index).toString()} + renderItem={({ item }: any) => ( + + {item.title} {/* Access item.title here */} + + )} + renderSectionHeader={({ section: { title } }: any) => ( + + {title} + + )} + /> + ); +}; + +describe('MySectionList component', () => { + const sections = [ + { + title: 'Section 1', + data: [ + { id: '1', title: 'Item 1' }, + { id: '2', title: 'Item 2' }, + ], + }, + { + title: 'Section 2', + data: [ + { id: '3', title: 'Item 3' }, + { id: '4', title: 'Item 4' }, + ], + }, + ]; + + it('renders section headers and items correctly', () => { + const { getByText } = render(); + + // Check if section headers are rendered + expect(getByText('Section 1')).toBeTruthy(); + expect(getByText('Section 2')).toBeTruthy(); + + // Check if items are rendered + expect(getByText('Item 1')).toBeTruthy(); + expect(getByText('Item 2')).toBeTruthy(); + expect(getByText('Item 3')).toBeTruthy(); + expect(getByText('Item 4')).toBeTruthy(); + }); +}); diff --git a/packages/components/src/system/base-elements.ts b/packages/components/src/system/base-elements.ts index d52e49c2..45c19103 100644 --- a/packages/components/src/system/base-elements.ts +++ b/packages/components/src/system/base-elements.ts @@ -6,6 +6,7 @@ import { Pressable as RNPressable, SafeAreaView as RNSafeAreaView, ScrollView as RNScrollView, + SectionList as RNSectionList, Text as RNText, TouchableHighlight as RNTouchableHighlight, TouchableOpacity as RNTouchableOpacity, @@ -29,6 +30,7 @@ export const baseRNElements = { ActivityIndicator: RNActivityIndicator, Slider: RNSlider, Flatlist: RNFlatList, + SectionList: RNSectionList, } as const; export type BaseRNElements = keyof typeof baseRNElements;