-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bako-id): improve name system box and add wrapper to apply anima…
…tion
- Loading branch information
1 parent
7fd4fd8
commit 771b084
Showing
5 changed files
with
173 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './names'; |
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,8 @@ | ||
export const MOCK_NAMES = [ | ||
{ | ||
name: '@bakoid', | ||
link: 'https://app.bako.id/profile/bakoid', | ||
resolver: | ||
'0xec8ff99af54e7f4c9dd81f32dffade6b41f3b980436ee2eabf47a069f998cd73', | ||
}, | ||
]; |
53 changes: 53 additions & 0 deletions
53
packages/app/src/systems/NameSystem/components/NameSystemBox.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,53 @@ | ||
import { Box, Button } from '@fuel-ui/react'; | ||
|
||
import { useState } from 'react'; | ||
import { | ||
NameSystemBox, | ||
type NameSystemBoxProps, | ||
NameSystemWrapper, | ||
} from '~/systems/NameSystem'; | ||
import { MOCK_NAMES } from '~/systems/NameSystem/__mocks__'; | ||
|
||
export default { | ||
component: NameSystemBox, | ||
title: 'NameSystem/Components/NameSystemBox', | ||
}; | ||
|
||
export const Usage = (args: NameSystemBoxProps) => { | ||
const { name: addressName, resolver, link } = MOCK_NAMES[0]; | ||
return ( | ||
<Box css={{ width: 270 }}> | ||
<NameSystemBox | ||
{...args} | ||
link={link} | ||
name={addressName} | ||
resolver={resolver} | ||
onClear={() => console.log('Clear')} | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
export const Wrapper = (args: NameSystemBoxProps) => { | ||
const { name: addressName, resolver, link } = MOCK_NAMES[0]; | ||
|
||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
return ( | ||
<Box css={{ width: 270 }}> | ||
<NameSystemWrapper | ||
isVisible={isVisible} | ||
element={ | ||
<NameSystemBox | ||
{...args} | ||
link={link} | ||
name={addressName} | ||
resolver={resolver} | ||
onClear={() => setIsVisible(false)} | ||
/> | ||
} | ||
input={<Button onPress={() => setIsVisible(true)}>Toggle</Button>} | ||
/> | ||
</Box> | ||
); | ||
}; |
100 changes: 60 additions & 40 deletions
100
packages/app/src/systems/NameSystem/components/NameSystemBox.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 |
---|---|---|
@@ -1,73 +1,93 @@ | ||
import { cssObj } from '@fuel-ui/css'; | ||
import { Box, Icon, IconButton, Input, Link, Text } from '@fuel-ui/react'; | ||
import { | ||
Avatar, | ||
Box, | ||
Icon, | ||
IconButton, | ||
Input, | ||
Link, | ||
Text, | ||
} from '@fuel-ui/react'; | ||
import { AnimatePresence, motion } from 'framer-motion'; | ||
import { type Maybe, animations, shortAddress } from '~/systems/Core'; | ||
|
||
const MotionContent = motion(Box); | ||
|
||
export type NameSystemWrapperProps = { | ||
isVisible?: boolean; | ||
element: React.ReactNode; | ||
input: React.ReactNode; | ||
}; | ||
|
||
export type NameSystemBoxProps = { | ||
link: Maybe<string>; | ||
name: Maybe<string>; | ||
resolver: Maybe<string>; | ||
isVisible?: boolean; | ||
onClear: () => void; | ||
children: React.ReactNode; | ||
}; | ||
|
||
export const NameSystemWrapper = (props: NameSystemWrapperProps) => ( | ||
<AnimatePresence mode="wait"> | ||
{props.isVisible ? ( | ||
<MotionContent {...animations.fadeIn()} key="name-system-primary"> | ||
{props.element} | ||
</MotionContent> | ||
) : ( | ||
<MotionContent {...animations.fadeIn()} key="name-system-secondary"> | ||
{props.input} | ||
</MotionContent> | ||
)} | ||
</AnimatePresence> | ||
); | ||
|
||
export const NameSystemBox = (props: NameSystemBoxProps) => { | ||
return ( | ||
<AnimatePresence mode="wait"> | ||
{props.isVisible ? ( | ||
<MotionContent | ||
{...animations.fadeIn()} | ||
key="name-system-box" | ||
as={Input} | ||
css={styles.addressBox} | ||
> | ||
<Link href={props.link ?? ''} isExternal> | ||
{props.name} | ||
</Link> | ||
<Text fontSize="sm"> | ||
{props.resolver && | ||
shortAddress(props.resolver, { | ||
left: 10, | ||
right: 18, | ||
})} | ||
</Text> | ||
<IconButton | ||
css={{ | ||
'.fuel_Icon': { color: '$inputBaseIcon !important' }, | ||
}} | ||
variant="link" | ||
aria-label="Clear" | ||
icon={Icon.is('X')} | ||
onPress={props.onClear} | ||
/> | ||
</MotionContent> | ||
) : ( | ||
<MotionContent key="name-system-children" {...animations.fadeIn()}> | ||
{props.children} | ||
</MotionContent> | ||
)} | ||
</AnimatePresence> | ||
<Box as={Input} css={styles.addressBox}> | ||
<Avatar.Generated size="xsm" hash={props.resolver ?? ''} /> | ||
<Box.Flex wrap="wrap" direction="column" justify="center"> | ||
<Link href={props.link ?? ''} isExternal> | ||
{props.name} | ||
</Link> | ||
<Text fontSize="xs"> | ||
{props.resolver && | ||
shortAddress(props.resolver, { | ||
left: 10, | ||
right: 10, | ||
})} | ||
</Text> | ||
</Box.Flex> | ||
<IconButton | ||
variant="link" | ||
aria-label="Clear" | ||
icon={Icon.is('X')} | ||
onPress={props.onClear} | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
const styles = { | ||
addressBox: cssObj({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
px: '$3 !important', | ||
py: '$1 !important', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
gap: '$3', | ||
flexDirection: 'row', | ||
position: 'relative', | ||
|
||
'.fuel_Link': { | ||
fontSize: '$sm', | ||
}, | ||
'.fuel_Button': { | ||
position: 'absolute', | ||
right: '$2', | ||
}, | ||
'.fuel_Avatar': { | ||
width: 30, | ||
height: 30, | ||
}, | ||
'.fuel_Icon': { | ||
color: '$inputBaseIcon !important', | ||
}, | ||
}), | ||
}; |
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