@team-monolith/cds 1.28.2 → 1.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,13 @@
1
1
  import React from "react";
2
2
  import { ButtonProps } from "../..";
3
- export interface SegmentedControlButtonProps extends Omit<ButtonProps, "color" | "size" | "startIcon" | "endIcon"> {
4
- value: string;
3
+ export interface SegmentedControlButtonProps<T> extends Omit<ButtonProps, "color" | "size" | "startIcon" | "endIcon" | "value"> {
4
+ value: T;
5
5
  startIcon?: React.ReactNode | ((isActive: boolean) => React.ReactNode);
6
6
  endIcon?: React.ReactNode | ((isActive: boolean) => React.ReactNode);
7
7
  }
8
8
  /**
9
9
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?node-id=181%3A89883)
10
10
  */
11
- export declare const SegmentedControlButton: React.ForwardRefExoticComponent<Omit<SegmentedControlButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
11
+ export declare const SegmentedControlButton: <T>(props: SegmentedControlButtonProps<T> & {
12
+ ref?: React.ComponentPropsWithRef<"button">["ref"];
13
+ }) => React.ReactElement;
@@ -14,11 +14,13 @@ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
14
14
  import styled from "@emotion/styled";
15
15
  import { css } from "@emotion/react";
16
16
  import React, { useContext } from "react";
17
- import { SegmentedControlGroupPropsContext } from "./SegmentedControlGroupPropsContext";
17
+ import { SegmentedControlGroupPropsContext, } from "./SegmentedControlGroupPropsContext";
18
18
  import { Button, shadows } from "../..";
19
19
  /**
20
20
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?node-id=181%3A89883)
21
21
  */
22
+ // https://fettblog.eu/typescript-react-generic-forward-refs/
23
+ // type assertion
22
24
  export const SegmentedControlButton = React.forwardRef(function SegmentedControlButton(props, ref) {
23
25
  const { onClick, startIcon, endIcon } = props, other = __rest(props, ["onClick", "startIcon", "endIcon"]);
24
26
  const context = useContext(SegmentedControlGroupPropsContext);
@@ -1,6 +1,6 @@
1
1
  import { ButtonSize, SquareButtonSize } from "../..";
2
2
  import React from "react";
3
- export type SegmentedControlGroupProps = {
3
+ export type SegmentedControlGroupProps<T = string> = {
4
4
  className?: string;
5
5
  component?: React.ElementType;
6
6
  children?: React.ReactNode;
@@ -14,14 +14,16 @@ export type SegmentedControlGroupProps = {
14
14
  /** 중복 선택 가능 유무 */
15
15
  multiSelect?: false;
16
16
  /** 선택된 값 */
17
- value: string | undefined;
18
- onChange?: (newValue: string) => void;
17
+ value: T | undefined;
18
+ onChange?: (newValue: T) => void;
19
19
  } | {
20
20
  multiSelect: true;
21
- value: string[];
22
- onChange?: (newValue: string[]) => void;
21
+ value: T[];
22
+ onChange?: (newValue: T[]) => void;
23
23
  });
24
24
  /**
25
25
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?node-id=181%3A89883)
26
26
  */
27
- export declare const SegmentedControlGroup: React.ForwardRefExoticComponent<SegmentedControlGroupProps & React.RefAttributes<HTMLDivElement>>;
27
+ export declare const SegmentedControlGroup: <T>(props: SegmentedControlGroupProps<T> & {
28
+ ref?: React.ComponentPropsWithRef<"div">["ref"];
29
+ }) => React.ReactElement;
@@ -1,14 +1,17 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { css, useTheme } from "@emotion/react";
4
- import { SegmentedControlGroupPropsContext } from "./SegmentedControlGroupPropsContext";
4
+ import { SegmentedControlGroupPropsContext, } from "./SegmentedControlGroupPropsContext";
5
5
  import React from "react";
6
6
  /**
7
7
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?node-id=181%3A89883)
8
8
  */
9
+ // https://fettblog.eu/typescript-react-generic-forward-refs/
10
+ // type assertion
9
11
  export const SegmentedControlGroup = React.forwardRef(function SegmentedControlGroup(props, ref) {
10
- const { component: Component = "div", className, children, fullWidth, disabled, multiSelect, } = props;
12
+ const { component: Component = "div", className, children, fullWidth, multiSelect, } = props;
11
13
  const theme = useTheme();
14
+ const Context = SegmentedControlGroupPropsContext;
12
15
  return (_jsx(Component, Object.assign({ ref: ref, className: className, css: css `
13
16
  display: flex;
14
17
  padding: 4px;
@@ -17,7 +20,7 @@ export const SegmentedControlGroup = React.forwardRef(function SegmentedControlG
17
20
  background-color: ${theme.color.background.neutralAlt};
18
21
  border-radius: 8px;
19
22
  border: 1px solid ${theme.color.background.neutralAltActive};
20
- ` }, { children: _jsx(SegmentedControlGroupPropsContext.Provider, Object.assign({ value: Object.assign(Object.assign({}, props), { onClick: (newValue) => {
23
+ ` }, { children: _jsx(Context.Provider, Object.assign({ value: Object.assign(Object.assign({}, props), { onClick: (newValue) => {
21
24
  var _a, _b, _c;
22
25
  if (multiSelect) {
23
26
  if (props.value.includes(newValue)) {
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { SegmentedControlGroupProps } from "./SegmentedControlGroup";
3
- export declare const SegmentedControlGroupPropsContext: import("react").Context<SegmentedControlGroupProps & {
4
- onClick?: ((newValue: string) => void) | undefined;
5
- }>;
3
+ export type SegmentedControlGroupPropsContextType<T> = SegmentedControlGroupProps<T> & {
4
+ onClick?: (newValue: T) => void;
5
+ };
6
+ export declare const SegmentedControlGroupPropsContext: import("react").Context<SegmentedControlGroupPropsContextType<any>>;
@@ -1,4 +1,5 @@
1
1
  import { createContext } from "react";
2
+ // TODO: type 추론을 더 잘해서 any를 제거하고 싶습니다.
2
3
  export const SegmentedControlGroupPropsContext = createContext({
3
4
  value: undefined,
4
5
  size: "medium",
@@ -1,10 +1,12 @@
1
1
  import React from "react";
2
2
  import { SquareButtonProps } from "../..";
3
- export interface SegmentedControlSquareButtonProps extends Omit<SquareButtonProps, "color" | "size" | "icon"> {
4
- value: string;
3
+ export interface SegmentedControlSquareButtonProps<T> extends Omit<SquareButtonProps, "color" | "size" | "icon"> {
4
+ value: T;
5
5
  icon: React.ReactNode | ((isActive: boolean) => React.ReactNode);
6
6
  }
7
7
  /**
8
8
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?node-id=181%3A89883)
9
9
  */
10
- export declare const SegmentedControlSquareButton: React.ForwardRefExoticComponent<Omit<SegmentedControlSquareButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
10
+ export declare const SegmentedControlSquareButton: <T>(props: SegmentedControlSquareButtonProps<T> & {
11
+ ref?: React.ComponentPropsWithRef<"button">["ref"];
12
+ }) => React.ReactElement;
@@ -15,10 +15,12 @@ import styled from "@emotion/styled";
15
15
  import { css } from "@emotion/react";
16
16
  import React, { useContext } from "react";
17
17
  import { shadows, SquareButton } from "../..";
18
- import { SegmentedControlGroupPropsContext } from "./SegmentedControlGroupPropsContext";
18
+ import { SegmentedControlGroupPropsContext, } from "./SegmentedControlGroupPropsContext";
19
19
  /**
20
20
  * [피그마](https://www.figma.com/file/PnQp3tPxiCjgsPZfLUaUL1/Codle-PD-Kit---Patterns?node-id=181%3A89883)
21
21
  */
22
+ // https://fettblog.eu/typescript-react-generic-forward-refs/
23
+ // type assertion
22
24
  export const SegmentedControlSquareButton = React.forwardRef(function SegmentedControlSquareButton(props, ref) {
23
25
  const { onClick, icon } = props, other = __rest(props, ["onClick", "icon"]);
24
26
  const context = useContext(SegmentedControlGroupPropsContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.28.2",
3
+ "version": "1.29.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,