Skip to content

Commit

Permalink
Added CheckBox examples, fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
lfernandezs committed Sep 13, 2022
1 parent 74f60a9 commit 62bb72e
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 36 deletions.
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BoxExamples from './components/BoxExamples';
import ButtonExamples from './components/ButtonExamples';
import IconExamples from './components/IconExamples';
import IconButtonExamples from './components/IconButtonExamples';
import CheckboxExamples from './components/CheckboxExamples';

const styles = StyleSheet.create( {
container: {
Expand Down Expand Up @@ -85,6 +86,7 @@ export default function App() {
<ButtonExamples />
<IconExamples />
<IconButtonExamples />
<CheckboxExamples />
</VStack>
</ScrollView>
</SafeAreaView>
Expand Down
64 changes: 64 additions & 0 deletions example/src/components/CheckboxExamples.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as React from 'react';

import { StyleSheet, View } from 'react-native';
import {
Checkbox, VStack, Text, HStack
} from '@amalgama/react-native-ui-kit';

const styles = StyleSheet.create( {
container: {
width: '100%',
marginBottom: 20
},
separator: {
height: 1,
minWidth: '100%',
marginTop: 2,
marginBottom: 6,
backgroundColor: 'black'
},
vspace: {
height: 10,
minWidth: '100%'
}
} );

const TextExamples = () => (
<VStack style={styles.container}>
<Text variant="h1" bgColor="primary.200">Checkbox Component</Text>
<View style={styles.vspace} />
<Text variant="sh1" color="primary.800">Enabled</Text>
<View style={styles.separator} />

<HStack>
<Checkbox></Checkbox>
<Checkbox isSelected></Checkbox>
<Checkbox isIndeterminated></Checkbox>
</HStack>

<View style={styles.vspace} />
<Text variant="sh1" color="primary.800">Disabled</Text>
<View style={styles.separator} />

<HStack>
<Checkbox disabled></Checkbox>
<Checkbox disabled isSelected></Checkbox>
<Checkbox disabled isIndeterminated></Checkbox>
</HStack>

<View style={styles.vspace} />
<Text variant="sh1" color="primary.800">Sizes and colors</Text>
<View style={styles.separator} />

<HStack space={'3'} marginX={'3'}>
<Checkbox __icon={{ size: 'xl' }} __unselected={{ __icon: { color: 'error.700' } }}></Checkbox>
<Checkbox isSelected __icon={{ size: 'lg' }} __selected={{ __icon: { color: 'success.500' } }}></Checkbox>
<Checkbox isIndeterminated __icon={{ size: 'md' }} __indeterminate={{ __icon: { color: 'warning.400' } }}></Checkbox>
</HStack>

<View style={styles.vspace} />

</VStack>
);

export default TextExamples;
3 changes: 1 addition & 2 deletions example/src/components/TextExamples.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { StyleSheet, View } from 'react-native';
import { CheckBox, Text, VStack } from '@amalgama/react-native-ui-kit';
import { Text, VStack } from '@amalgama/react-native-ui-kit';

const styles = StyleSheet.create( {
container: {
Expand All @@ -23,7 +23,6 @@ const styles = StyleSheet.create( {

const TextExamples = () => (
<VStack style={styles.container}>
<CheckBox style={{ marginVertical: 10 }}></CheckBox>
<Text variant="h1" bgColor="primary.200">Text Component</Text>
<View style={styles.vspace} />
<Text variant="sh1" color="primary.800">Variants</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export { HStack, VStack } from './main/Stack';
export { default as Text } from './main/Text';
export { default as Icon } from './main/Icon';
export { default as IconButton } from './main/IconButton';
export { default as CheckBox } from './main/CheckBox';
export { default as Checkbox } from './main/Checkbox';
22 changes: 11 additions & 11 deletions src/components/main/CheckBox/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useMemo } from 'react';
import useIsPressed from '../../hooks/useIsPressed';
import { useComponentPropsResolver } from '../../../hooks';
import useIsSelected from '../../hooks/useIsSelected';
import type { ICheckBoxProps } from './types';
import type { ICheckboxProps } from './types';
import type { IIconProps } from '../Icon/types';

interface IUseCheckBoxPropsResolverReturnType {
iconProps: ICheckBoxProps['__icon'],
containerProps: Omit<ICheckBoxProps, '__icon'>
icon: string
interface IUseCheckboxPropsResolverReturnType {
iconProps: IIconProps,
containerProps: Omit<ICheckboxProps, '__icon'>
}

// Poner esto en otro lado
Expand All @@ -17,12 +17,12 @@ const selectIcon = ( isIndeterminated: boolean, isSelected: boolean ): string =>
return 'customuncheckedbox';
};

export const useCheckBoxPropsResolver = ( {
export const useCheckboxPropsResolver = ( {
isSelected: isSelectedProp = false,
isIndeterminated: isIndeterminatedProp = false,
...props
} : ICheckBoxProps
): IUseCheckBoxPropsResolverReturnType => {
} : ICheckboxProps
): IUseCheckboxPropsResolverReturnType => {
const { disabled } = props;

const {
Expand All @@ -41,16 +41,16 @@ export const useCheckBoxPropsResolver = ( {
isPressed
} ), [ isSelected, isIndeterminated, disabled, isPressed ] );

const icon = selectIcon( isIndeterminated, isSelected );
const name = selectIcon( isIndeterminated, isSelected );

const {
__icon: iconProps,
...containerProps
} = useComponentPropsResolver( 'CheckBox', props, state ) as ICheckBoxProps;
} = useComponentPropsResolver( 'Checkbox', props, state ) as ICheckboxProps;

containerProps.onPress = onPress;
containerProps.onPressIn = onPressIn;
containerProps.onPressOut = onPressOut;

return { icon, iconProps, containerProps };
return { iconProps: { ...iconProps, name }, containerProps };
};
14 changes: 7 additions & 7 deletions src/components/main/CheckBox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React from 'react';
import Icon from '../Icon';
import Pressable from '../Pressable';
import { useCheckBoxPropsResolver } from './hooks';
import type { ICheckBoxProps } from './types';
import { useCheckboxPropsResolver } from './hooks';
import type { ICheckboxProps } from './types';

const CheckBox = ( {
const Checkbox = ( {
isSelected = false,
isIndeterminated = false,
...props
}: ICheckBoxProps ) => {
const { icon, iconProps, containerProps } = useCheckBoxPropsResolver( {
}: ICheckboxProps ) => {
const { iconProps, containerProps } = useCheckboxPropsResolver( {
isIndeterminated, isSelected, ...props
} );

return (
<Pressable {...containerProps}>
<Icon name={icon} {...containerProps} {...iconProps}></Icon>
<Icon {...iconProps}></Icon>
</Pressable>
);
};

export default CheckBox;
export default Checkbox;
6 changes: 3 additions & 3 deletions src/components/main/CheckBox/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ComponentStyledProps } from '../../../core/components/types';
import type { IPressableProps } from '../Pressable/types';

export interface ICheckBoxProps extends Omit<IPressableProps, 'children' | 'size'>,
ComponentStyledProps<'CheckBox'>
export interface ICheckboxProps extends Omit<IPressableProps, 'children' | 'size'>,
ComponentStyledProps<'Checkbox'>
{
isSelected?: boolean,
isIndeterminated?:boolean,
isIndeterminated?:boolean
}
2 changes: 1 addition & 1 deletion src/core/components/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StyledProps } from '../../theme/types';

export type ComponentName = 'Text' | 'Box' | 'Stack' | 'Button' | 'Pressable' | 'Icon' | 'IconButton' | 'CheckBox';
export type ComponentName = 'Text' | 'Box' | 'Stack' | 'Button' | 'Pressable' | 'Icon' | 'IconButton' | 'Checkbox';

export type VariantName = string;

Expand Down
11 changes: 5 additions & 6 deletions src/core/theme/defaultTheme/components/CheckBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ export default {
justifyContent: 'center',
alignItems: 'center',
rounded: 'full',
__icon: {
},
__selected: {
color: 'secondary.900',
__icon: { color: 'secondary.900' },
borderColor: 'secondary.900'
},
__unselected: {
color: 'neutral.800',
__icon: { color: 'neutral.800' },
borderColor: 'neutral.800'
},
__indeterminate: {
color: 'secondary.900',
__icon: { color: 'secondary.900' },
borderColor: 'secondary.900'
},
__disabled: {
Expand All @@ -31,6 +29,7 @@ export default {
__focus: {
bg: 'secondary.10',
borderWidth: '1'
}
},
__icon: { }
}
};
4 changes: 2 additions & 2 deletions src/core/theme/defaultTheme/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Button from './Button';
import Icon from './Icon';
import IconButton from './IconButton';
import Stack from './Stack';
import CheckBox from './CheckBox';
import Checkbox from './Checkbox';

export default {
Text,
Icon,
IconButton,
Button,
Stack,
CheckBox
Checkbox
};
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export {
IconButton,
VStack,
Text,
CheckBox
Checkbox
} from './components';
4 changes: 2 additions & 2 deletions web_example/src/components/TextExamples.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { StyleSheet, View } from 'react-native';
import { Text, VStack, CheckBox } from '@amalgama/react-native-ui-kit';
import { Text, VStack, Checkbox } from '@amalgama/react-native-ui-kit';

const styles = StyleSheet.create( {
container: {
Expand All @@ -23,7 +23,7 @@ const styles = StyleSheet.create( {

const TextExamples = () => (
<VStack style={styles.container}>
<CheckBox></CheckBox>
<Checkbox></Checkbox>
<Text variant="h1" bgColor="primary.200">Text Component</Text>
<View style={styles.vspace} />
<Text variant="sh1" color="primary.800">Variants</Text>
Expand Down

0 comments on commit 62bb72e

Please sign in to comment.