| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- import {
- useLayoutEffect,
- useState
- } from "react";
- import {
- View
- } from "react-native";
- import stylesheet from "./stylesheet";
- import {
- NCoreUIKitLocalize,
- NCoreUIKitTheme,
- PageContainer,
- CodeViewer,
- SelectBox,
- TextInput,
- Header,
- Switch,
- Chip,
- Text
- } from "ncore-ui-kit";
- import {
- useNavigation
- } from "@react-navigation/native";
- import type RootStackParamList from "../../../navigation/type";
- import type {
- NativeStackNavigationProp
- } from "@react-navigation/native-stack";
- import type {
- IChipProps
- } from "ncore-ui-kit";
- const CHIP_TYPES: Array<IChipProps["type"]> = [
- "primary",
- "danger",
- "warning",
- "success",
- "info"
- ];
- const CHIP_SPREAD_BEHAVIOURS: Array<IChipProps["spreadBehaviour"]> = [
- "baseline",
- "free"
- ];
- const CHIP_SIZES: Array<IChipProps["size"]> = [
- "small",
- "medium",
- "large"
- ];
- const CHIP_TYPES_DATA = CHIP_TYPES.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const CHIP_SPREAD_BEHAVIOURS_DATA = CHIP_SPREAD_BEHAVIOURS.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const CHIP_SIZES_DATA = CHIP_SIZES.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const ChipPage = () => {
- const {
- radiuses,
- borders,
- spaces,
- colors
- } = NCoreUIKitTheme.useContext();
- const {
- localize
- } = NCoreUIKitLocalize.useContext();
- const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
- const [
- spreadIndex,
- setSpreadIndex
- ] = useState<number>(0);
- const [
- typeIndex,
- setTypeIndex
- ] = useState<number>(0);
- const [
- sizeIndex,
- setSizeIndex
- ] = useState<number>(1);
- const [
- isClosable,
- setIsClosable
- ] = useState<boolean>(true);
- const [
- isDisabled,
- setIsDisabled
- ] = useState<boolean>(false);
- const [
- isLoading,
- setIsLoading
- ] = useState<boolean>(false);
- const [
- title,
- setTitle
- ] = useState<string>("Chip Title");
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => <Header
- title={localize("chip-title")}
- isWrapSafeareaContext={false}
- navigation={navigation}
- isGoBackEnable={true}
- />,
- headerShown: true
- });
- }, []);
- return <PageContainer
- scrollViewProps={{
- contentContainerStyle: stylesheet.scrollContent
- }}
- isWorkWithHeaderSpace={false}
- scrollViewStyle={[
- stylesheet.container
- ]}
- isScrollable={true}
- >
- <View
- style={[
- stylesheet.contentContainer
- ]}
- >
- <Text
- style={stylesheet.descText}
- variant="bodyMediumSize"
- color="mid"
- >
- {localize("chip-desc")}
- </Text>
- <View
- style={[
- stylesheet.previewContainer,
- {
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd
- }
- ]}
- >
- <Chip
- spreadBehaviour={CHIP_SPREAD_BEHAVIOURS[spreadIndex]}
- type={CHIP_TYPES[typeIndex]}
- size={CHIP_SIZES[sizeIndex]}
- isClosable={isClosable}
- isDisabled={isDisabled}
- isLoading={isLoading}
- title={title}
- />
- </View>
- <View
- style={{
- marginBottom: spaces.spacingMd
- }}
- >
- <Text
- style={{
- marginBottom: spaces.spacingSm
- }}
- variant="headlineSmallSize"
- >
- {localize("usage")}
- </Text>
- <CodeViewer
- code={"import {\n Chip\n} from \"ncore-ui-kit\";\n\n<Chip\n title=\"Chip Title\"\n type=\"primary\"\n size=\"medium\"\n/>"}
- language="tsx"
- />
- </View>
- <TextInput
- placeholder={localize("chip-enterText")}
- title={localize("chip-titleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setTitle}
- value={title}
- />
- <View
- style={[
- stylesheet.rowContainer,
- {
- gap: spaces.spacingMd
- }
- ]}
- >
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = CHIP_TYPES.indexOf(
- selectedItems[0]!
- .__key as IChipProps["type"],
- );
- if (index !== -1) setTypeIndex(index);
- }
- }}
- initialSelectedItems={
- CHIP_TYPES_DATA[typeIndex]
- ? [
- CHIP_TYPES_DATA[typeIndex]!
- ]
- : []
- }
- titleExtractor={(item) => item.__title}
- title={localize("chip-changeType")}
- keyExtractor={(item) => item.__key}
- spreadBehaviour="free"
- data={CHIP_TYPES_DATA}
- />
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = CHIP_SPREAD_BEHAVIOURS.indexOf(
- selectedItems[0]!
- .__key as IChipProps["spreadBehaviour"],
- );
- if (index !== -1) setSpreadIndex(index);
- }
- }}
- initialSelectedItems={
- CHIP_SPREAD_BEHAVIOURS_DATA[spreadIndex]
- ? [
- CHIP_SPREAD_BEHAVIOURS_DATA[spreadIndex]!
- ]
- : []
- }
- titleExtractor={(item) => item.__title}
- title={localize("chip-changeSpread")}
- keyExtractor={(item) => item.__key}
- data={CHIP_SPREAD_BEHAVIOURS_DATA}
- spreadBehaviour="free"
- />
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = CHIP_SIZES.indexOf(
- selectedItems[0]!
- .__key as IChipProps["size"],
- );
- if (index !== -1) setSizeIndex(index);
- }
- }}
- initialSelectedItems={
- CHIP_SIZES_DATA[sizeIndex]
- ? [
- CHIP_SIZES_DATA[sizeIndex]!
- ]
- : []
- }
- titleExtractor={(item) => item.__title}
- title={localize("chip-changeSize")}
- keyExtractor={(item) => item.__key}
- data={CHIP_SIZES_DATA}
- spreadBehaviour="free"
- />
- <View
- style={stylesheet.switchesContainer}
- >
- <Switch
- title={localize("chip-toggleClosable")}
- onPress={() => {
- setIsClosable(!isClosable);
- }}
- spreadBehaviour="free"
- isActive={isClosable}
- />
- <Switch
- title={localize("chip-toggleLoading")}
- onPress={() => {
- setIsLoading(!isLoading);
- }}
- spreadBehaviour="free"
- isActive={isLoading}
- />
- <Switch
- title={localize("chip-toggleDisabled")}
- onPress={() => {
- setIsDisabled(!isDisabled);
- }}
- spreadBehaviour="free"
- isActive={isDisabled}
- />
- </View>
- </View>
- </View>
- </PageContainer>;
- };
- export default ChipPage;
|