Skip to content
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

Add ToggleEmojiButtonGroup and ToggleEmojiButtonSource component #2301

Merged

Conversation

yangwooseong
Copy link
Collaborator

@yangwooseong yangwooseong commented Jun 21, 2024

Self Checklist

  • I wrote a PR title in English and added an appropriate label to the PR.
  • I wrote the commit message in English and to follow the Conventional Commits specification.
  • I added the changeset about the changes that needed to be released. (or didn't have to)
  • I wrote or updated documentation related to the changes. (or didn't have to)
  • I wrote or updated tests related to the changes. (or didn't have to)
  • I tested the changes in various browsers. (or didn't have to)
    • Windows: Chrome, Edge, (Optional) Firefox
    • macOS: Chrome, Edge, Safari, (Optional) Firefox

Related Issue

Summary

  • ToggleEmojiButtonGroupToggleEmojiButtonSource 컴포넌트를 구현합니다.

Details

  • fillDirection="all" 일 때 컨테이너에 넘치지 않을 만큼 가로 세로 1:1 비율로 늘어나는 스타일을 css 로 구현하는 것이 어려웠습니다. aspect-ration: 1/1, width: 100%, height: auto 로 시도해봤으나, 컨테이너가 100px * 50px 의 크기를 가질 때 버튼이 100px * 100px 로 되버리는 문제가 있었습니다. 어쩔 수 없이 js로 계산해서 resizeObserver까지 다는 방식으로 구현했습니다.
  • ToggleEmojiButtonSource컴포넌트안에 이모지를 보여줄때, imageUrl를 props로 열여주는 것도 생각했지만 이렇게 하면 모바일에서 구현이 어려운 문제가 있어서 content속성을 그대로 활용했습니다.

Breaking change? (Yes/No)

  • No

References

@yangwooseong yangwooseong added the feat:component Issue or PR related to a new component label Jun 21, 2024
@yangwooseong yangwooseong self-assigned this Jun 21, 2024
Copy link

changeset-bot bot commented Jun 21, 2024

🦋 Changeset detected

Latest commit: f7a9162

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@channel.io/bezier-react Patch
bezier-figma-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

channeltalk bot commented Jun 21, 2024

Copy link
Contributor

github-actions bot commented Jun 21, 2024

Chromatic Report

🚀 Congratulations! Your build was successful!

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 38 lines in your changes missing coverage. Please review.

Project coverage is 82.27%. Comparing base (8e6fb64) to head (f7a9162).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ToggleEmojiButtonGroup/useToggleEmojiButtonSize.ts 0.00% 24 Missing ⚠️
...aToggleEmojiButtonGroup/ToggleEmojiButtonGroup.tsx 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2301      +/-   ##
==========================================
- Coverage   83.28%   82.27%   -1.01%     
==========================================
  Files         141      143       +2     
  Lines        2943     2979      +36     
  Branches      899      904       +5     
==========================================
  Hits         2451     2451              
- Misses        487      523      +36     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@sungik-choi sungik-choi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToggleEmojiButtonSource컴포넌트안에 이모지를 보여줄때, imageUrl를 props로 열여주는 것도 생각했지만 이렇게 하면 모바일에서 구현이 어려운 문제가 있어서 content속성을 그대로 활용했습니다.

혹시 구체적으로 어떤 문제인지 알 수 있을까요?

@sungik-choi
Copy link
Contributor

요거는 이모지 기획 변경 & 적용되면 다시 리뷰할게요

@yangwooseong yangwooseong marked this pull request as draft July 3, 2024 05:26
@yangwooseong yangwooseong force-pushed the WEB-1983/toggle-icon-button branch 3 times, most recently from 8bb023f to 1c44d57 Compare October 30, 2024 01:48
@yangwooseong yangwooseong marked this pull request as ready for review October 30, 2024 02:08
Comment on lines 9 to 13
/**
* If `loading` is true, spinner will be shown, replacing the content.
* @default false
*/
loading?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마이너) 토글 버튼 전반에 스펙에는 존재하지 않는 loading prop을 미리 만들어둘 필요가 있을까? 생각이 문득 들었습니다 🤔 사용할 일이 거의 없을 거 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요 저도 지워도 될것같습니다

Comment on lines 166 to 137
<ToggleGroup.Root
type="single"
defaultValue={defaultValue}
onValueChange={onValueChange}
value={value}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToggleGroup.Root 가 div를 렌더하고 있기 때문에, DOM 크기를 줄이기 위해 추가 div없이 이를 컨테이너로 활용하는게 좋을 거 같아요.

const mergedRefs = useMergeRefs(ref, forwardedRef)
const { fillDirection } = useToggleEmojiButtonContext()

const { adjustButtonSize } = useResizeButton({ button: ref.current })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 구조에선 버튼 컴포넌트마다 컨테이너에 ResizeObserver를 붙이는데, 컨테이너당 하나의 ResizeObserver만 붙이도록 개선할 수 있을 거 같습니다.

useResizeButton (useEffect)를 컨테이너에서만 호출하고, 버튼의 사이즈(React state)를 반환하도록 한 뒤에 이를 컨텍스트를 통해 전달하면 될 거 같아요. 어차피 동일한 컨테이너의 모든 버튼은 동일한 사이즈를 가질거니까요.

아래는 간단하게 작성한 예시입니다..!

interface UseResizeButtonProps {
  container: HTMLElement | null
  childrenSize: number
}

// NOTE: 네이밍은 적절히 수정
export function useResizeButton({
  container,
  childrenSize,
}: UseResizeButtonProps) {
  const [buttonSize, setButtonSize] = useState<number>(EMOJI_BUTTON_SIZE)
  const { fillDirection } = useToggleEmojiButtonContext()

  const adjustButtonSize = useCallback(() => {
    if (!container || fillDirection !== 'all') {
      return
    }

    const containerWidth = container.clientWidth
    const containerHeight = container.clientHeight
    const size = Math.max(
      Math.min(
        (containerWidth - EMOJI_BUTTON_GROUP_GAP * (childrenSize - 1)) /
          childrenSize,
        containerHeight - EMOJI_BUTTON_GROUP_GAP
      ),
      EMOJI_BUTTON_SIZE
    )

    setButtonSize(size)
  }, [childrenSize, container, fillDirection])

  /* ... */

  return buttonSize
}
/* container */
const buttonSize = useResizeButton({
  container: ref,
  childrenSize: React.Children.count(children),
})

/* button */
const { buttonSize, fillDirection } = useToggleEmojiButtonContext()

 <BaseButton
  ref={mergedRefs}
  // onResize={handleResize}
  style={
    {
      '--b-toggle-emoji-button-size': cssDimension(EMOJI_BUTTON_SIZE),
      '--b-toggle-emoji-button-emoji-size': cssDimension(EMOJI_SIZE),
      width:
        fillDirection === 'all' ? cssDimension(buttonSize) : undefined,
      height:
        fillDirection === 'all' ? cssDimension(buttonSize) : undefined,
      ...style,
    } as CSSProperties
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각해보니 컨테이너에서 컨텍스트로 주지 않고 컨테이너의 css variable로 전달해주기만 해도 되겠네요..!


const { adjustButtonSize } = useResizeButton({ button: ref.current })

const handleResize: ReactEventHandler<HTMLButtonElement> = (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 이벤트 핸들러가 꼭 필요한가요? 컨테이너의 리사이즈 이벤트 핸들러에서 처리해줄 거로 보여서요!

const shouldResizeButton = fillDirection === 'all'
const resizedButtonSize = useResizeButton({
container: ref,
enable: shouldResizeButton,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enable: shouldResizeButton,
enabled: shouldResizeButton,

(마이너)

},
forwardedRef
) {
const [ref, setRef] = useState<null | HTMLDivElement>(null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [ref, setRef] = useState<null | HTMLDivElement>(null)
const [container, setContainer] = useState<null | HTMLDivElement>(null)

(마이너) React RefObject가 아니라서 이 네이밍이 더 적절해보여요

buttonCount: number
}

export function useResizeButton({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(마이너) useToggleEmojiButtonSize 같은 이름은 어떤가요? 버튼 사이즈를 반환한다는 점이 더 잘 드러난다고 생각해요. 지금 이름은 아무것도 반환하지 않을 거 같은 뉘앙스가 있는 거 같아요..!

@yangwooseong yangwooseong merged commit 26658dc into channel-io:main Nov 6, 2024
7 of 9 checks passed
@yangwooseong yangwooseong deleted the WEB-1983/toggle-icon-button branch November 6, 2024 07:00
yangwooseong pushed a commit that referenced this pull request Nov 6, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @channel.io/[email protected]

### Minor Changes

- The use client directive has been added at the top of all components
inside @channel.io/bezier-react.
([#2468](#2468)) by
@nayounsang

### Patch Changes

- Remove 1px gap between icon and text in `s` size `AlphaButton`,
`AlphaFloatingButton`.
([#2484](#2484)) by
@yangwooseong

- Apply hovered color token for `AlphaButton`, `AlphaFloatingButton`,
and `AlphaFloatingIconButton`.
([#2471](#2471)) by
@yangwooseong

- Add `ToggleEmojiButtonGroup` and `ToggleEmojiButtonSource` component.
([#2301](#2301)) by
@yangwooseong

-   Updated dependencies
    -   @channel.io/[email protected]

## @channel.io/[email protected]

### Patch Changes

- Change `alpha-color-green-300-0` alpha token.
([#2471](#2471)) by
@yangwooseong
Modify hovered color generating formula so that they are more visible in
dark theme.

## @channel.io/[email protected]

### Patch Changes

-   Updated dependencies
    -   @channel.io/[email protected]

## [email protected]

### Patch Changes

-   Updated dependencies
    -   @channel.io/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat:component Issue or PR related to a new component
Projects
No open projects
Status: 📌 Backlog
Development

Successfully merging this pull request may close these issues.

2 participants