-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,393 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { YStack } from 'tamagui' | ||
import Checkbox from './Checkbox' | ||
|
||
export default { | ||
title: 'Checkbox', | ||
component: Checkbox, | ||
} | ||
|
||
export const Default = () => ( | ||
<YStack> | ||
<Checkbox /> | ||
<Checkbox checked /> | ||
<Checkbox disabled /> | ||
<Checkbox checked disabled /> | ||
</YStack> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { ComponentPropsWithoutRef, ComponentRef, forwardRef } from 'react' | ||
import { createStyledContext, GetThemeValueForKey, getVariableValue, styled } from '@tamagui/core' | ||
import { Check } from '@tamagui/lucide-icons' | ||
import { ThemeableStack } from '@tamagui/stacks' | ||
|
||
export const CheckboxContext = createStyledContext({ | ||
checked: false, | ||
disabled: false, | ||
}) | ||
|
||
export const CheckboxGroupZone = styled(ThemeableStack, { | ||
tag: 'button', | ||
context: CheckboxContext, | ||
focusable: true, | ||
height: 34, | ||
width: 34, | ||
borderRadius: 1000, | ||
group: true, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
cursor: 'pointer', | ||
animation: 'bouncy', | ||
'$group-hover': { backgroundColor: '$blue2' }, | ||
focusStyle: { | ||
backgroundColor: '$blue2', | ||
}, | ||
hoverStyle: { | ||
backgroundColor: '$blue2', | ||
}, | ||
disabledStyle: { | ||
cursor: 'not-allowed', | ||
opacity: 0.4, | ||
backgroundColor: 'transparent', | ||
}, | ||
variants: { | ||
checked: { | ||
true: {}, | ||
}, | ||
} as const, | ||
}) | ||
|
||
export const CheckboxGroupItemFrame = styled(ThemeableStack, { | ||
context: CheckboxContext, | ||
animation: 'bouncy', | ||
borderRadius: 2, | ||
height: 18, | ||
width: 18, | ||
backgroundColor: 'transparent', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
borderWidth: 1, | ||
borderColor: '$textSecondary', | ||
padding: 0, | ||
|
||
variants: { | ||
checked: { | ||
true: { | ||
borderColor: '$gray7', | ||
}, | ||
}, | ||
} as const, | ||
}) | ||
|
||
export const CheckboxGroupIndicatorFrame = styled(ThemeableStack, { | ||
context: CheckboxContext, | ||
width: 18, | ||
height: 18, | ||
animation: 'bouncy', | ||
borderColor: 'transparent', | ||
borderRadius: 2, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
scale: 0, | ||
variants: { | ||
checked: { | ||
true: { | ||
backgroundColor: '$gray7', | ||
// borderColor: '$gray7', | ||
scale: 1, | ||
}, | ||
}, | ||
} as const, | ||
}) | ||
|
||
export default forwardRef<ComponentRef<typeof CheckboxGroupZone>, ComponentPropsWithoutRef<typeof CheckboxGroupZone> & { color?: 'blue' | 'gray' }>(function ( | ||
{ color = 'blue', ...props }, | ||
ref, | ||
) { | ||
const hintColor = color === 'gray' ? '$gray7' : '$blue9' | ||
return ( | ||
<CheckboxGroupZone {...props} ref={ref}> | ||
<CheckboxGroupItemFrame borderColor={props.checked ? hintColor : '$textSecondary'}> | ||
<CheckboxGroupIndicatorFrame backgroundColor={props.checked ? hintColor : undefined}> | ||
<Check size={14} color="white1" /> | ||
</CheckboxGroupIndicatorFrame> | ||
</CheckboxGroupItemFrame> | ||
</CheckboxGroupZone> | ||
) | ||
}) |
18 changes: 18 additions & 0 deletions
18
src/components/base/CheckboxGroup/CheckboxGroup.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import CheckboxGroup from './CheckboxGroup' | ||
|
||
export default { | ||
title: 'CheckboxGroup', | ||
component: CheckboxGroup, | ||
} | ||
|
||
const list = [ | ||
{ label: 'Option 1', value: 'option1' }, | ||
{ label: 'Option 2', value: 'option2' }, | ||
{ label: 'Option 3', value: 'option3' }, | ||
] | ||
|
||
export const Default = () => { | ||
const [value, setValue] = React.useState(['option1']) | ||
return <CheckboxGroup options={list} value={value} onChange={setValue} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useState } from 'react' | ||
import Checkbox from '@/components/base/Checkbox/Checkbox' | ||
import Text from '@/components/base/Text' | ||
import { styled } from '@tamagui/core' | ||
import { ThemeableStack, XStack } from 'tamagui' | ||
|
||
type CheckboxGroupProps = { | ||
options: { | ||
label: string | ||
value: string | ||
}[] | ||
value: string[] | ||
onChange: (value: string[]) => void | ||
} | ||
|
||
const CheckboxGroupFrame = styled(ThemeableStack, { | ||
gap: '$3', | ||
flexDirection: 'row', | ||
flexWrap: 'wrap', | ||
// justifyContent: 'space-between',s | ||
}) | ||
|
||
export default function CheckboxGroup({ options, value, onChange }: CheckboxGroupProps) { | ||
const handlePress = (item: string) => () => { | ||
if (value.includes(item)) { | ||
onChange(value.filter((v) => v !== item)) | ||
return | ||
} | ||
onChange([...value, item]) | ||
} | ||
|
||
const isChecked = (item: string) => value.includes(item) | ||
return ( | ||
<CheckboxGroupFrame> | ||
{options.map((option) => ( | ||
<XStack | ||
key={option.value} | ||
flexGrow={1} | ||
flexShrink={1} | ||
flexBasis={'48%'} | ||
$md={{ flexBasis: '100%' }} | ||
gap="$2" | ||
group | ||
onPress={handlePress(option.value)} | ||
alignItems="center" | ||
cursor="pointer" | ||
> | ||
<Checkbox checked={isChecked(option.value)} /> | ||
<Text.MD multiline>{option.label}</Text.MD> | ||
</XStack> | ||
))} | ||
</CheckboxGroupFrame> | ||
) | ||
} |
Oops, something went wrong.