Skip to content

Commit

Permalink
Merge pull request #54 from vitiacat/main
Browse files Browse the repository at this point in the history
Fixed Chip
  • Loading branch information
levkopo authored Jan 1, 2025
2 parents 5fcbf07 + 41aa108 commit c251105
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: Install and Build
run: |
yarn set version berry
yarn config set -H enableImmutableInstalls false
yarn
yarn run build
yarn run build:styleguide
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"typescript": "^4.9.5",
"typescript-plugin-styled-components": "^2.0.0"
},
"packageManager": "yarn@4.3.1",
"packageManager": "yarn@4.6.0",
"dependencies": {
"@emotion/css": "^11.13.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/chip/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ZnUI Radio component
# ZnUI Chip component
[![npm version](https://buttons.fury.io/js/@znui%2Fchip.svg)](https://buttons.fury.io/js/@znui%2Fchip)

## Documentation
Expand Down
41 changes: 19 additions & 22 deletions packages/chip/src/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {StateLayer, Tappable} from "@znui/ripple";
import {znui, ZnUIStyleObject} from "@znui/base";

export interface ChipProps extends LayoutProps {
mode?: 'outlined' | 'elevated' | 'filled'
leading?: ReactElement
avatar?: ReactElement
trailingIcon?: ReactElement
Expand All @@ -29,16 +28,10 @@ export interface ChipProps extends LayoutProps {
disabled?: boolean
}

const variantStyles: Record<keyof ChipProps['variant'], ZnUIStyleObject> = {
'outline': {},
'filled': {
bg: ThemeTokens.secondaryContainer,
borderColor: undefined,
border: undefined
},
'tonal': {
bg: ThemeTokens.onSurfaceVariant
}
const variantBackgrounds: Record<keyof ChipProps['variant'], string> = {
'outline': 'transparent',
'filled': ThemeTokens.secondaryContainer,
'tonal': ThemeTokens.onSurfaceVariant
}

/**
Expand All @@ -60,13 +53,19 @@ export const Chip = React.forwardRef(
...otherProps
} = props

const finalVariant = useMemo(() => selected ? 'filled' : variant, [selected])
const finalLeading = useMemo(() => selected ? <znui.svg
xmlns="http://www.w3.org/2000/svg"
width={24} height={24} viewBox="0 0 24 24" fill="none"
>
<path d="M 7.4 11 L 10 13.6 L 16.6 7 L 18 8.4 L 10 16.4 L 10 16.4 L 6 12.4 L 7.4 11" fill={disabled ? ThemeTokens.onSurface : ThemeTokens.primary} />
</znui.svg> : leading, [selected, disabled])
const finalVariant = useMemo(() => selected ? 'filled' : variant, [selected, variant]);
const finalLeading = selected ? (
<znui.svg
xmlns="http://www.w3.org/2000/svg"
width={24}
height={24}
viewBox="0 0 24 24"
fill="none"
>
<path d="M 7.4 11 L 10 13.6 L 16.6 7 L 18 8.4 L 10 16.4 L 10 16.4 L 6 12.4 L 7.4 11" fill={disabled ? ThemeTokens.onSurface : ThemeTokens.primary} />
</znui.svg>
) : leading


return <HStack
pos='relative'
Expand All @@ -79,7 +78,7 @@ export const Chip = React.forwardRef(
pr={trailingIcon ? 8 : 16}
boxSizing='border-box'
h='32px'
border='solid 1px'
border={variant != 'filled' ? 'solid 1px' : undefined}
alignItems='center'
borderColor={disabled && variant != 'outline' ? 'transparent' : ThemeTokens.outlineVariant}
spacing={8}
Expand All @@ -93,11 +92,9 @@ export const Chip = React.forwardRef(
bg: 'currentColor'
},
}}
{...variantStyles[finalVariant]}
bg='transparent'
{...otherProps}
>
<Layout pos='absolute' top={0} left={0} bg={disabled && finalVariant != 'outline' ? ThemeTokens.onSurfaceVariant : variantStyles[finalVariant]['bg']} oc={finalVariant == 'tonal' || disabled ? 0.12 : 1}
<Layout pos='absolute' top={0} left={0} bg={disabled && finalVariant != 'outline' ? ThemeTokens.onSurfaceVariant : variantBackgrounds[finalVariant]} oc={finalVariant == 'tonal' || disabled ? 0.12 : 1}
layoutSize='100%'/>
{onClick && <StateLayer/>}
{finalLeading && !avatar && <IconWrapper oc={disabled ? 0.38 : 1} zIndex={1} c={selected ? ThemeTokens.onSecondaryContainer : (disabled ? ThemeTokens.onSurface : ThemeTokens.primary)} size={18}>
Expand Down
4 changes: 2 additions & 2 deletions packages/md3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@znui/card": "^1.3.0-alpha",
"@znui/carousel": "^1.3.0-alpha",
"@znui/checkbox": "^1.3.0-alpha",
"@znui/chip": "^1.3.0-alpha",
"@znui/coordinator-layout": "^1.3.0-alpha",
"@znui/divider": "^1.3.0-alpha",
"@znui/layouts": "^1.3.0-alpha",
Expand All @@ -46,8 +47,7 @@
"@znui/text-fields": "^1.3.0-alpha",
"@znui/tooltip": "^1.3.0-alpha",
"@znui/typography": "^1.3.0-alpha",
"@znui/utils": "^1.3.0-alpha",
"@znui/chip": "^1.3.0-alpha"
"@znui/utils": "^1.3.0-alpha"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3097,7 +3097,7 @@ __metadata:
languageName: unknown
linkType: soft

"@znui/chip@workspace:packages/chip":
"@znui/chip@npm:^1.3.0-alpha, @znui/chip@workspace:packages/chip":
version: 0.0.0-use.local
resolution: "@znui/chip@workspace:packages/chip"
dependencies:
Expand Down Expand Up @@ -3365,6 +3365,7 @@ __metadata:
"@znui/card": "npm:^1.3.0-alpha"
"@znui/carousel": "npm:^1.3.0-alpha"
"@znui/checkbox": "npm:^1.3.0-alpha"
"@znui/chip": "npm:^1.3.0-alpha"
"@znui/coordinator-layout": "npm:^1.3.0-alpha"
"@znui/divider": "npm:^1.3.0-alpha"
"@znui/layouts": "npm:^1.3.0-alpha"
Expand Down

0 comments on commit c251105

Please sign in to comment.