Skip to content

Commit

Permalink
feat(design-system): bump version 0.28.15
Browse files Browse the repository at this point in the history
  • Loading branch information
abretonc7s committed Oct 13, 2024
1 parent 9d5da65 commit 6d1a91b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/design-system/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@siteed/design-system",
"version": "0.28.14",
"version": "0.28.15",
"author": "Arthur Breton <[email protected]> (https://github.com/deeeed)",
"license": "MIT",
"repository": {
Expand Down
74 changes: 73 additions & 1 deletion packages/design-system/src/components/picker/PickerContent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { useCallback, useMemo, useState } from 'react';
import { StyleSheet, View } from 'react-native';
import { Chip, Searchbar, Text } from 'react-native-paper';
import { Chip, IconButton, Searchbar, Text } from 'react-native-paper';
import { AppTheme } from '../../hooks/_useAppThemeSetup';
import { useModal } from '../../hooks/useModal/useModal';
import { useTheme } from '../../providers/ThemeProvider';
import { ConfirmCancelFooter } from '../bottom-modal/footers/ConfirmCancelFooter';
import { Result } from '../Result/Result';
import { SelectOption } from '../SelectButtons/SelectButtons';
import { TextInput } from '../TextInput/TextInput';

const getStyles = (theme: AppTheme) => {
return StyleSheet.create({
Expand All @@ -23,6 +26,19 @@ const getStyles = (theme: AppTheme) => {
optionItem: {
marginBottom: theme.spacing.margin,
},
debugCreateButton: {
alignSelf: 'flex-end',
marginTop: theme.spacing.margin,
},
createOptionContainer: {
padding: theme.spacing.padding,
},
createOptionInput: {
marginBottom: theme.spacing.margin,
},
createOptionButton: {
marginTop: theme.spacing.margin,
},
});
};

Expand All @@ -39,6 +55,7 @@ interface PickerContentProps {
emptyActionLabel: string;
onChange: (options: SelectOption[]) => void;
onItemPress?: (item: SelectOption) => void;
showDebugCreate?: boolean;
}

export const PickerContent: React.FC<PickerContentProps> = ({
Expand All @@ -53,12 +70,14 @@ export const PickerContent: React.FC<PickerContentProps> = ({
noResultsText,
onChange,
onItemPress,
showDebugCreate = true,
}) => {
const theme = useTheme();
const styles = useMemo(() => getStyles(theme), [theme]);
const [searchQuery, setSearchQuery] = useState('');

const [tempOptions, setTempOptions] = useState(options);
const { openDrawer } = useModal();

const filteredOptions = useMemo(() => {
return tempOptions.filter((option) =>
Expand All @@ -83,6 +102,52 @@ export const PickerContent: React.FC<PickerContentProps> = ({
[tempOptions, multi, onChange, onItemPress]
);

const handleCreate = useCallback(async () => {
try {
const newOption = await openDrawer<SelectOption>({
initialData: {
value: `new-option-${Date.now()}`,
label: '',
selected: false,
},
title: 'Create New Option',
bottomSheetProps: {
enableDynamicSizing: true,
},
render: ({ data, onChange }) => {
return (
<View style={styles.createOptionContainer}>
<TextInput
autoFocus
label="New Option Label"
value={data?.label}
onChangeText={(text) => onChange({ ...data, label: text })}
style={styles.createOptionInput}
/>
</View>
);
},
renderFooter: ({ resolve, data }) => {
return (
<ConfirmCancelFooter
onCancel={() => resolve(undefined)}
onFinish={() => resolve(data)}
/>
);
},
});

console.log('after drawernewOption', newOption);
if (newOption) {
const updatedOptions = [...tempOptions, newOption];
setTempOptions(updatedOptions);
onChange(updatedOptions);
}
} catch (error) {
console.error('Error creating new option', error);
}
}, [openDrawer, tempOptions, onChange]);

const renderOptions = useCallback(() => {
return (
<View style={styles.optionsContainer}>
Expand Down Expand Up @@ -134,6 +199,13 @@ export const PickerContent: React.FC<PickerContentProps> = ({
) : (
renderOptions()
)}
{showDebugCreate && (
<IconButton
icon="plus"
onPress={handleCreate}
style={styles.debugCreateButton}
/>
)}
</View>
);
};

0 comments on commit 6d1a91b

Please sign in to comment.