@ncds/ui-admin 1.8.21-alpha.1 → 1.8.21-alpha.2

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.
Files changed (22) hide show
  1. package/dist/cjs/src/components/forms-and-input/input-base/InputBase.js +11 -5
  2. package/dist/cjs/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +116 -0
  3. package/dist/cjs/src/components/forms-and-input/password-input/PasswordInput.js +3 -3
  4. package/dist/cjs/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js +59 -0
  5. package/dist/cjs/src/generated/scoped-css.js +1 -1
  6. package/dist/esm/src/components/forms-and-input/input-base/InputBase.js +11 -5
  7. package/dist/esm/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +116 -0
  8. package/dist/esm/src/components/forms-and-input/password-input/PasswordInput.js +3 -3
  9. package/dist/esm/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js +56 -0
  10. package/dist/esm/src/generated/scoped-css.js +1 -1
  11. package/dist/temp/src/components/forms-and-input/input-base/InputBase.d.ts +1 -1
  12. package/dist/temp/src/components/forms-and-input/input-base/InputBase.js +9 -5
  13. package/dist/temp/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +79 -0
  14. package/dist/temp/src/components/forms-and-input/password-input/PasswordInput.js +2 -2
  15. package/dist/temp/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.d.ts +1 -0
  16. package/dist/temp/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js +48 -0
  17. package/dist/temp/src/generated/scoped-css.js +1 -1
  18. package/dist/types/src/components/forms-and-input/input-base/InputBase.d.ts +1 -1
  19. package/dist/types/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.d.ts +1 -0
  20. package/dist/ui-admin/assets/styles/style.css +35 -2
  21. package/dist/ui-admin/assets/styles/style.scoped.css +35 -2
  22. package/package.json +1 -1
@@ -25,7 +25,7 @@ interface InputSideCustomSlot {
25
25
  placement?: 'inside' | 'outside';
26
26
  }
27
27
  type InputLeadingSlotType = InputSideTextSlot | InputSideIconSlot | InputSideCustomSlot;
28
- type InputTrailingSlotType = InputSideButtonSlot | InputSideIconSlot | InputSideCustomSlot;
28
+ type InputTrailingSlotType = InputSideButtonSlot | InputSideTextSlot | InputSideIconSlot | InputSideCustomSlot;
29
29
  interface InputBaseCommonProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
30
30
  required?: boolean;
31
31
  label?: string;
@@ -32,7 +32,7 @@ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled
32
32
  input.removeEventListener('input', syncFromInput);
33
33
  };
34
34
  }, [props.value]);
35
- const renderOutsideSlot = (slot) => {
35
+ const renderOutsideSlot = (slot, position) => {
36
36
  if (slot.type === 'custom' && slot.placement !== 'outside') {
37
37
  return null;
38
38
  }
@@ -40,7 +40,7 @@ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled
40
40
  case 'button':
41
41
  return (_jsx("button", { type: slot.isSubmit ? 'submit' : 'button', className: classNames('ncua-input__button', `ncua-input__button--${size}`), onClick: slot.onClick, children: slot.label }));
42
42
  case 'text':
43
- return (_jsx("span", { className: classNames('ncua-input__leading-text', `ncua-input__leading-text--${size}`), children: slot.text }));
43
+ return (_jsx("span", { className: classNames(`ncua-input__${position}-text`, `ncua-input__${position}-text--${size}`), children: slot.text }));
44
44
  case 'custom':
45
45
  return slot.children;
46
46
  default:
@@ -51,7 +51,10 @@ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled
51
51
  switch (slot.type) {
52
52
  case 'icon': {
53
53
  const SlotIcon = slot.icon;
54
- return (_jsx("div", { className: "ncua-input__icon-wrap", children: _jsx(SlotIcon, { className: classNames(`ncua-input__${position}-icon`, slot.className), color: slot.color ? COLOR[slot.color] : undefined, width: slot.size ?? iconSvgSize[size], height: slot.size ?? iconSvgSize[size] }) }));
54
+ return (_jsx("div", { className: "ncua-input__icon-wrap", children: _jsx(SlotIcon, { className: classNames(`ncua-input__${position}-icon`,
55
+ // color 를 지정하지 않았을 때만 상태별 색(Placeholder/Filled/Focused/Disabled)을 CSS 에 맡긴다.
56
+ // 지정한 경우에는 이 클래스를 붙이지 않아 지정 색이 그대로 유지된다.
57
+ { 'ncua-input__slot-icon': !slot.color }, slot.className), color: slot.color ? COLOR[slot.color] : undefined, width: slot.size ?? iconSvgSize[size], height: slot.size ?? iconSvgSize[size] }) }));
55
58
  }
56
59
  case 'custom':
57
60
  if (slot.placement !== 'inside') {
@@ -87,8 +90,9 @@ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled
87
90
  'full-width': fullWidth,
88
91
  'ncua-input__trailing-button': trailingElement?.type === 'button',
89
92
  'ncua-input__leading-text-wrap': leadingElement?.type === 'text',
93
+ 'ncua-input__trailing-text-wrap': trailingElement?.type === 'text',
90
94
  'has-value': hasValue,
91
- }, className), children: [renderLabel(), _jsxs("div", { className: "ncua-input__content-wrap", children: [_jsxs("div", { className: "ncua-input__content", children: [leadingElement && renderOutsideSlot(leadingElement), _jsxs("div", { className: classNames('ncua-input__field', `ncua-input__field--${size}`), children: [leadingElement && renderInsideSlot(leadingElement, 'left'), _jsx("input", { ref: (node) => {
95
+ }, className), children: [renderLabel(), _jsxs("div", { className: "ncua-input__content-wrap", children: [_jsxs("div", { className: "ncua-input__content", children: [leadingElement && renderOutsideSlot(leadingElement, 'leading'), _jsxs("div", { className: classNames('ncua-input__field', `ncua-input__field--${size}`), children: [leadingElement && renderInsideSlot(leadingElement, 'left'), _jsx("input", { ref: (node) => {
92
96
  if (typeof ref === 'function') {
93
97
  ref(node);
94
98
  }
@@ -96,6 +100,6 @@ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled
96
100
  ref.current = node;
97
101
  }
98
102
  inputRef.current = node;
99
- }, type: "text", disabled: disabled, maxLength: maxLength, ...props }), renderClearButton(), renderStatusIcon(), trailingElement && renderInsideSlot(trailingElement, 'right')] }), trailingElement && renderOutsideSlot(trailingElement)] }), showTextCount && maxLength && (_jsxs("div", { className: "ncua-input__field-text-count", children: [_jsx("output", { className: "ncua-input__field-text-count-current", children: textCount }), _jsxs("span", { children: ["/", maxLength] })] }))] }), hintText && (_jsx(HintText, { className: "ncua-input__hint-text", destructive: destructive, children: hintText }))] }));
103
+ }, type: "text", disabled: disabled, maxLength: maxLength, ...props }), renderClearButton(), renderStatusIcon(), trailingElement && renderInsideSlot(trailingElement, 'right')] }), trailingElement && renderOutsideSlot(trailingElement, 'trailing')] }), showTextCount && maxLength && (_jsxs("div", { className: "ncua-input__field-text-count", children: [_jsx("output", { className: "ncua-input__field-text-count-current", children: textCount }), _jsxs("span", { children: ["/", maxLength] })] }))] }), hintText && (_jsx(HintText, { className: "ncua-input__hint-text", destructive: destructive, children: hintText }))] }));
100
104
  });
101
105
  export { InputBase };
@@ -4,6 +4,7 @@ import { createElement } from 'react';
4
4
  import { createRoot } from 'react-dom/client';
5
5
  import { act } from 'react-dom/test-utils';
6
6
  import { describe, expect, it, vi } from 'vitest';
7
+ import { COLOR } from '../../../../../constant/color';
7
8
  import { InputBase } from '../InputBase';
8
9
  // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
9
10
  globalThis.IS_REACT_ACT_ENVIRONMENT = true;
@@ -107,6 +108,42 @@ describe('InputBase — 아이콘 사이즈', () => {
107
108
  view.unmount();
108
109
  });
109
110
  });
111
+ describe('InputBase — 슬롯 아이콘 상태 색상', () => {
112
+ // 상태별 색은 CSS 가 결정한다. jsdom 에서는 스타일시트를 로드하지 않으므로
113
+ // "상태 규칙을 타는 클래스가 붙었는지" 와 "지정 색이 인라인으로 남았는지" 로 검증한다.
114
+ const leftIconOf = (container) => container.querySelector('.ncua-input__left-icon');
115
+ it('color 를 지정하지 않으면 상태 색상 클래스가 붙는다', () => {
116
+ // Given/When: color 없이 슬롯 아이콘을 렌더하면
117
+ const view = mountInputBase({ leadingElement: { type: 'icon', icon: SearchLg } });
118
+ // Then: 상태 규칙을 타는 클래스가 붙고, 인라인 색은 지정되지 않는다
119
+ const icon = leftIconOf(view.container);
120
+ expect(icon?.classList.contains('ncua-input__slot-icon')).toBe(true);
121
+ expect(icon?.hasAttribute('color')).toBe(false);
122
+ view.unmount();
123
+ });
124
+ it('color 를 지정하면 상태 색상 클래스가 붙지 않고 지정 색이 유지된다', () => {
125
+ // Given/When: color 를 지정해 렌더하면
126
+ const view = mountInputBase({
127
+ leadingElement: { type: 'icon', icon: SearchLg, color: 'blue500' },
128
+ });
129
+ // Then: 상태 규칙에서 제외되고 지정한 색이 그대로 남는다
130
+ const icon = leftIconOf(view.container);
131
+ expect(icon?.classList.contains('ncua-input__slot-icon')).toBe(false);
132
+ expect(icon?.getAttribute('color')).toBe(COLOR.blue500);
133
+ view.unmount();
134
+ });
135
+ it('slot.className 을 함께 주어도 상태 색상 클래스가 유지된다', () => {
136
+ // Given/When: className 을 추가로 넘기면
137
+ const view = mountInputBase({
138
+ leadingElement: { type: 'icon', icon: SearchLg, className: 'my-icon' },
139
+ });
140
+ // Then: 두 클래스가 모두 붙는다
141
+ const icon = leftIconOf(view.container);
142
+ expect(icon?.classList.contains('ncua-input__slot-icon')).toBe(true);
143
+ expect(icon?.classList.contains('my-icon')).toBe(true);
144
+ view.unmount();
145
+ });
146
+ });
110
147
  describe('InputBase — has-value 상태 클래스', () => {
111
148
  const typeInto = (container, text) => {
112
149
  const input = container.querySelector('input');
@@ -152,3 +189,45 @@ describe('InputBase — has-value 상태 클래스', () => {
152
189
  view.unmount();
153
190
  });
154
191
  });
192
+ describe('InputBase — 텍스트 슬롯', () => {
193
+ it('leadingElement 텍스트는 leading 클래스와 wrap 클래스가 붙는다', () => {
194
+ const { container, unmount } = mountInputBase({
195
+ leadingElement: { type: 'text', text: 'https://' },
196
+ });
197
+ const text = container.querySelector('.ncua-input__leading-text');
198
+ expect(text?.textContent).toBe('https://');
199
+ expect(container.querySelector('.ncua-input__leading-text-wrap')).not.toBeNull();
200
+ unmount();
201
+ });
202
+ it('trailingElement 텍스트는 trailing 클래스와 wrap 클래스가 붙는다', () => {
203
+ const { container, unmount } = mountInputBase({
204
+ trailingElement: { type: 'text', text: 'px' },
205
+ });
206
+ const text = container.querySelector('.ncua-input__trailing-text');
207
+ expect(text?.textContent).toBe('px');
208
+ expect(container.querySelector('.ncua-input__trailing-text-wrap')).not.toBeNull();
209
+ // leading 클래스가 섞이면 모서리·테두리 방향이 반대가 된다
210
+ expect(container.querySelector('.ncua-input__leading-text')).toBeNull();
211
+ unmount();
212
+ });
213
+ it('trailingElement 텍스트는 입력 필드 뒤에 온다', () => {
214
+ const { container, unmount } = mountInputBase({
215
+ trailingElement: { type: 'text', text: 'px' },
216
+ });
217
+ const content = container.querySelector('.ncua-input__content');
218
+ const children = Array.from(content?.children ?? []);
219
+ const fieldIndex = children.findIndex((el) => el.classList.contains('ncua-input__field'));
220
+ const textIndex = children.findIndex((el) => el.classList.contains('ncua-input__trailing-text'));
221
+ expect(fieldIndex).toBeGreaterThanOrEqual(0);
222
+ expect(textIndex).toBeGreaterThan(fieldIndex);
223
+ unmount();
224
+ });
225
+ it('사이즈 modifier 가 함께 붙는다', () => {
226
+ const { container, unmount } = mountInputBase({
227
+ size: 'sm',
228
+ trailingElement: { type: 'text', text: 'px' },
229
+ });
230
+ expect(container.querySelector('.ncua-input__trailing-text--sm')).not.toBeNull();
231
+ unmount();
232
+ });
233
+ });
@@ -19,8 +19,8 @@ export const PasswordInput = forwardRef(({ size = 'xs', ...props }, ref) => {
19
19
  return (_jsx(InputBase, { ref: ref, size: size, type: isVisible ? 'text' : 'password', leadingElement: {
20
20
  type: 'icon',
21
21
  icon: Lock01,
22
- // 색은 CSS가 결정한다 여기서 props.value로 판정하면 uncontrolled Input에서 영원히 빈 값 취급된다
23
- className: 'ncua-input__password-lock-icon',
22
+ // color 넘기지 않아 슬롯 아이콘 공통 규칙(상태별 색)을 그대로 따른다.
23
+ // 여기서 props.value 로 판정하면 uncontrolled Input 에서 영원히 빈 값 취급된다.
24
24
  }, trailingElement: {
25
25
  type: 'custom',
26
26
  placement: 'inside',
@@ -0,0 +1,48 @@
1
+ // @vitest-environment jsdom
2
+ import { createElement } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { act } from 'react-dom/test-utils';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { PasswordInput } from '../PasswordInput';
7
+ // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
8
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
9
+ function mountPasswordInput(props = {}) {
10
+ const container = document.createElement('div');
11
+ document.body.appendChild(container);
12
+ const root = createRoot(container);
13
+ act(() => {
14
+ root.render(createElement(PasswordInput, props));
15
+ });
16
+ const unmount = () => {
17
+ act(() => {
18
+ root.unmount();
19
+ });
20
+ container.remove();
21
+ };
22
+ return { container, unmount };
23
+ }
24
+ describe('PasswordInput — 자물쇠 아이콘 색상', () => {
25
+ // 자물쇠 색은 CSS 가 결정한다. 인라인 color 를 넘기면 상태 규칙이 무시되므로,
26
+ // "인라인 색이 없고 슬롯 아이콘 공통 클래스를 탄다" 는 것이 색상 반영의 전제다.
27
+ it('자물쇠에 인라인 색을 넘기지 않고 슬롯 아이콘 공통 클래스를 탄다', () => {
28
+ // Given/When: 기본 상태로 렌더하면
29
+ const view = mountPasswordInput();
30
+ // Then: 상태 규칙을 타는 클래스가 붙고 인라인 색은 없다
31
+ const lockIcon = view.container.querySelector('.ncua-input__left-icon');
32
+ expect(lockIcon).not.toBeNull();
33
+ expect(lockIcon?.classList.contains('ncua-input__slot-icon')).toBe(true);
34
+ expect(lockIcon?.hasAttribute('color')).toBe(false);
35
+ view.unmount();
36
+ });
37
+ // 값이 있는 채로 비활성화되면 has-value 가 살아 있어 자물쇠가 진하게 남던 문제
38
+ it('값이 있는 채로 disabled 여도 자물쇠가 상태 규칙 대상으로 남는다', () => {
39
+ // Given/When: 값이 있는 비활성화 상태로 렌더하면
40
+ const view = mountPasswordInput({ value: 'secret', disabled: true, onChange: vi.fn() });
41
+ // Then: 루트에 is-disabled 와 has-value 가 함께 붙고, 자물쇠는 공통 클래스를 유지한다
42
+ const root = view.container.querySelector('.ncua-input');
43
+ expect(root?.classList.contains('is-disabled')).toBe(true);
44
+ expect(root?.classList.contains('has-value')).toBe(true);
45
+ expect(view.container.querySelector('.ncua-input__left-icon')?.classList.contains('ncua-input__slot-icon')).toBe(true);
46
+ view.unmount();
47
+ });
48
+ });