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

Writing code to convert common mixin interpolation to CSS Variable #1778

Closed
Tracked by #1800
sungik-choi opened this issue Dec 6, 2023 · 0 comments · Fixed by #1787
Closed
Tracked by #1800

Writing code to convert common mixin interpolation to CSS Variable #1778

sungik-choi opened this issue Dec 6, 2023 · 0 comments · Fixed by #1787
Assignees
Labels
bezier-codemod Issue or PR related to bezier-codemod enhancement Issues or PR related to making existing features better

Comments

@sungik-choi
Copy link
Contributor

sungik-choi commented Dec 6, 2023

Description

styled backtick 내부의 공용 mixin interpolation을 매칭되는 CSS Variable로 변환하는 codemod 스크립트를 작성합니다.

Reasons for suggestion

styled-components를 제거하면서 더 이상 bezier-react 공용 mixin interpolation을 export 하지 않도록 바뀝니다. 이제 기존 Mixin은 CSS Variable/컴포넌트를 통해 사용해야합니다. 이를 사용처에서 쉽게 마이그레이션할 수 있도록 변환 코드 작성이 필요합니다.

Proposed solution

export const Box = styled.div`
  /* AS-IS */
  ${inputTextStyle}
  /* TO-BE */
  color: var(--txt-black-darkest); /* placeholder color는 _base.scss에 정의되어 있음 */

  /* AS-IS */
  ${inputWrapperStyle}
  /* TO-BE */
  box-shadow: var(--input-box-shadow);

  /* AS-IS */
  ${focusedInputWrapperStyle}
  /* TO-BE */
  box-shadow: var(--input-box-shadow-focused);

  /* AS-IS */
  ${erroredInputWrapperStyle}
  /* TO-BE */
  box-shadow: var(--input-box-shadow-invalid);

  /* 변환을 자동화하기 어려운 믹스인들 */

  ${Typography.*}
  /* -> 제거, Text의 typo 옵션을 사용하는 방식으로 대체 */

  ${ellipsis()}
  /* -> 제거, Text의 truncated 옵션으로 대체 */
  /* truncated 옵션이 lineHeight까지 포함할 수 있도록 개선해야 함 */

  ${smoothCorners()}
  /* -> 제거, AlphaSmoothCornersBox를 사용 */

  ${absoluteCenter()}
  /* -> 제거, Center 컴포넌트 등을 통해 제공 예정 */

  ${centeredBackgroundImage()}
  /* -> 제거, 사용처에서 직접 정의하도록 변경 예정  */

  ${disableAutoMinimum()}
  /* -> 제거, 사용처에서 직접 정의하도록 변경 예정 */

  ${hideScrollbars()}
  /* -> 제거, 사용처에서 직접 정의하도록 변경 예정 */

  ${backgroundImageVariable()}
  /* -> 제거, 사용처에서 직접 정의하도록 변경 예정 */
`

References

@sungik-choi sungik-choi added the enhancement Issues or PR related to making existing features better label Dec 6, 2023
@github-project-automation github-project-automation bot moved this to 📌 Backlog in Bezier React Dec 6, 2023
@yangwooseong yangwooseong moved this from 📌 Backlog to 🏃‍♀️ In progress in Bezier React Dec 7, 2023
@yangwooseong yangwooseong moved this from 🏃‍♀️ In progress to 📌 Backlog in Bezier React Dec 7, 2023
@yangwooseong yangwooseong moved this from 📌 Backlog to 🏃‍♀️ In progress in Bezier React Dec 13, 2023
yangwooseong added a commit that referenced this issue Dec 13, 2023
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] 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
<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

- FIxes #1778

## Summary
<!-- Please brief explanation of the changes made -->

- Mixin interpolation 을 css variable 을 사용한 스타일 코드로 변환하는 codemod 를 추가합니다.
- As-is
```typescript
import { 
  styled, 
  inputWrapperStyle, 
  focusedInputWrapperStyle, 
  erroredInputWrapperStyle,
} from '@channel.io/bezier-react'

const Wrapper = styled.div`
  position: relative;
  background-color: ${({ foundation }) =>
    foundation?.theme?.['bg-grey-lightest']};
  border-radius: 12px;
  ${inputWrapperStyle};
  ${({ focus }) => focus && focusedInputWrapperStyle};
  ${({ focus, whisper }) => focus && whisper && erroredInputWrapperStyle};
`
```

- To-be
```typescript
import {
  styled, css
} from '@channel.io/bezier-react'

const Wrapper = styled.div`
  position: relative;
  background-color: ${({ foundation }) =>
    foundation?.theme?.['bg-grey-lightest']};
  border-radius: 12px;
  box-shadow: var(--input-box-shadow);
  ${({ focus }) => focus && css`
  box-shadow: var(--input-box-shadow-focused);
`};
  ${({ focus, whisper }) => focus && whisper && css`
  box-shadow: var(--input-box-shadow-invalid);
`};
`
```



## Details
<!-- Please elaborate description of the changes -->

- import 관련 유틸을 추가합니다.
- 여러 줄에 걸친 코드로 변경할 때 인덴트까지 잘 유지하면서 변경하는 것이 쉽지 않아서, 이 부분은 사용처의 포매팅을 기대해야
할 것 같네요.

### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->

- No

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->

- [Ts-morph](https://ts-morph.com/)
- [AST
Viewer](https://ts-ast-viewer.com/#code/JYWwDg9gTgLgBAbzgKDnAzjAngGwKYAmANCmsAHZgCuMA6lAIZhh5QDK2+JqcAZhAGMq6QgElKNekxbtOebmlZRoYiXUbNWHXPOQBfPspBwA5AAEBACwblyeHADpgEAPQAjPAC9grALRQ8BgEYE2RkAQhyTDgpTSg4AF4MOQIHAmAANwADHkh0YBhncgAuOACcBkKMvABuHjcggGsAc2UqcgJfCJxoUoASBAAKJH52gkqiuD0ASkSAPh40UY6JyIB+BxhLPBA8DYBtEzdm31a8LF8cYGbLGDxMEwBdPTq0N2gCP0Z04VKARgATGAAB6vOADCjUdTSLRyF48AbDPiCYRTWYJObIoToOAAMlxWOEqihsRk2nw8LQiJGKPQJAA7pZgOgZGj5oScfi4IzmayuUoVARxCSNGS4XUskA)
@github-project-automation github-project-automation bot moved this from 🏃‍♀️ In progress to ✅ Done in Bezier React Dec 13, 2023
@sungik-choi sungik-choi mentioned this issue Dec 15, 2023
@yangwooseong yangwooseong added the bezier-codemod Issue or PR related to bezier-codemod label Dec 15, 2023
yangwooseong added a commit that referenced this issue Jan 18, 2024
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] 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
<!-- Please link to issue if one exists -->

- #1778

## Summary
<!-- Please brief explanation of the changes made -->

- `inputPlaceholderStyle` mixin 에 대한 변환 로직을 codemod 에 추가하고 README를 업데이트
했습니다.

### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->

- No

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->

- None
yangwooseong added a commit that referenced this issue Jan 19, 2024
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] 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
<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

- #1778

## Summary
<!-- Please brief explanation of the changes made -->

- 사용처가 매우 적긴 하지만, `${Rounding.round12}` 와 같은 경우가 interpolation 변환
codemod 에서 누락되어서 이를 추가합니다.

## Details
<!-- Please elaborate description of the changes -->

- Foundation 의 경우 theme, border, elevation 등을 한번에 묶어서 변환하는 codemod가
있습니다. 이것처럼 interpolation 역시 한번에 묶어서 변환하는 codemod 를 추가하고, 다음과 같이 naming 을
변경합니다.
- `v2-typography-interpolation-to-css-variable` ->
`v2-interpolation-to-css-variable-typography`
- `v2-input-interpolation-to-css-variable` ->
`v2-interpolation-to-css-variable-input`
- `v2-z-index-interpolation-to-css-variable` ->
`v2-interpolation-to-css-variable-z-index`
- `v2-interpolation-to-css-variable`: 위 transform 들을 모두 실행 

### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->

- No

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->

- None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bezier-codemod Issue or PR related to bezier-codemod enhancement Issues or PR related to making existing features better
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants