-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ShareDropdownMenu component #38
Conversation
| 'posts.share.facebook' | ||
| 'posts.share.linkedin', | ||
string | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The situation where a key is only available in one of the languages is not complementary, so it is defined as a type.
string | ||
> | ||
|
||
export type TranslationFn = <K extends keyof Dictionary>(key: K) => string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defined as a type for ease of definition in component props.
export const ShareDropdownMenu: FC<Props> = ({ children, t }) => { | ||
return ( | ||
<DropdownMenuRoot> | ||
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trigger will be this component:
<DropdownMenuContent sideOffset={5} align="start"> | ||
<DropdownMenuItem | ||
leftIcon={<CopyIcon className={styles.icon} />} | ||
onSelect={() => alert('Item 1 clicked')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual copying process will be implemented in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
import styles from './ShareDropdownMenu.module.css' | ||
|
||
type Props = PropsWithChildren<{ | ||
t: TranslationFn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Q]
I was thinking it might be okay to use 'lang' as a props, but is there a specific reason why you chose to pass the 't' function as a props?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because it is easier for child components to be maintained if they are initialized in the page component and t
is passed around. I refer to the implementation in i18next.
ref: https://locize.com/blog/next-app-dir-i18n/
- No need to worry about SC / CC distinction.
- No need to worry about
getTranslation
becoming an async function. - Components do not have to worry about implementing
getTranslation
for clients, for example, to retrieve lang from localStorage.
- No need to worry about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! 😄
I understand now that considering the async case of SC, passing 't' as a prop makes it unnecessary to maintain the child component.
> Conflicts: > frontend/apps/service-site/package.json > frontend/pnpm-lock.yaml
implement styling for ShareDropdownMenu component.
2024-10-10.20.12.43.mov
https://service-site-storybook-8c9ytuopb-route-06-plain-core.vercel.app/?path=/story/features-posts-components-sharedropdownmenu--default