@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
@@ -52,7 +52,7 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
52
52
  input.removeEventListener('input', syncFromInput);
53
53
  };
54
54
  }, [props.value]);
55
- const renderOutsideSlot = slot => {
55
+ const renderOutsideSlot = (slot, position) => {
56
56
  if (slot.type === 'custom' && slot.placement !== 'outside') {
57
57
  return null;
58
58
  }
@@ -66,7 +66,7 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
66
66
  });
67
67
  case 'text':
68
68
  return _jsx("span", {
69
- className: classNames('ncua-input__leading-text', `ncua-input__leading-text--${size}`),
69
+ className: classNames(`ncua-input__${position}-text`, `ncua-input__${position}-text--${size}`),
70
70
  children: slot.text
71
71
  });
72
72
  case 'custom':
@@ -83,7 +83,12 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
83
83
  return _jsx("div", {
84
84
  className: "ncua-input__icon-wrap",
85
85
  children: _jsx(SlotIcon, {
86
- className: classNames(`ncua-input__${position}-icon`, slot.className),
86
+ className: classNames(`ncua-input__${position}-icon`,
87
+ // color 를 지정하지 않았을 때만 상태별 색(Placeholder/Filled/Focused/Disabled)을 CSS 에 맡긴다.
88
+ // 지정한 경우에는 이 클래스를 붙이지 않아 지정 색이 그대로 유지된다.
89
+ {
90
+ 'ncua-input__slot-icon': !slot.color
91
+ }, slot.className),
87
92
  color: slot.color ? COLOR[slot.color] : undefined,
88
93
  width: slot.size ?? iconSvgSize[size],
89
94
  height: slot.size ?? iconSvgSize[size]
@@ -155,13 +160,14 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
155
160
  'full-width': fullWidth,
156
161
  'ncua-input__trailing-button': trailingElement?.type === 'button',
157
162
  'ncua-input__leading-text-wrap': leadingElement?.type === 'text',
163
+ 'ncua-input__trailing-text-wrap': trailingElement?.type === 'text',
158
164
  'has-value': hasValue
159
165
  }, className),
160
166
  children: [renderLabel(), _jsxs("div", {
161
167
  className: "ncua-input__content-wrap",
162
168
  children: [_jsxs("div", {
163
169
  className: "ncua-input__content",
164
- children: [leadingElement && renderOutsideSlot(leadingElement), _jsxs("div", {
170
+ children: [leadingElement && renderOutsideSlot(leadingElement, 'leading'), _jsxs("div", {
165
171
  className: classNames('ncua-input__field', `ncua-input__field--${size}`),
166
172
  children: [leadingElement && renderInsideSlot(leadingElement, 'left'), _jsx("input", {
167
173
  ref: node => {
@@ -177,7 +183,7 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
177
183
  maxLength: maxLength,
178
184
  ...props
179
185
  }), renderClearButton(), renderStatusIcon(), trailingElement && renderInsideSlot(trailingElement, 'right')]
180
- }), trailingElement && renderOutsideSlot(trailingElement)]
186
+ }), trailingElement && renderOutsideSlot(trailingElement, 'trailing')]
181
187
  }), showTextCount && maxLength && _jsxs("div", {
182
188
  className: "ncua-input__field-text-count",
183
189
  children: [_jsx("output", {
@@ -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;
@@ -130,6 +131,55 @@ describe('InputBase — 아이콘 사이즈', () => {
130
131
  view.unmount();
131
132
  });
132
133
  });
134
+ describe('InputBase — 슬롯 아이콘 상태 색상', () => {
135
+ // 상태별 색은 CSS 가 결정한다. jsdom 에서는 스타일시트를 로드하지 않으므로
136
+ // "상태 규칙을 타는 클래스가 붙었는지" 와 "지정 색이 인라인으로 남았는지" 로 검증한다.
137
+ const leftIconOf = container => container.querySelector('.ncua-input__left-icon');
138
+ it('color 를 지정하지 않으면 상태 색상 클래스가 붙는다', () => {
139
+ // Given/When: color 없이 슬롯 아이콘을 렌더하면
140
+ const view = mountInputBase({
141
+ leadingElement: {
142
+ type: 'icon',
143
+ icon: SearchLg
144
+ }
145
+ });
146
+ // Then: 상태 규칙을 타는 클래스가 붙고, 인라인 색은 지정되지 않는다
147
+ const icon = leftIconOf(view.container);
148
+ expect(icon?.classList.contains('ncua-input__slot-icon')).toBe(true);
149
+ expect(icon?.hasAttribute('color')).toBe(false);
150
+ view.unmount();
151
+ });
152
+ it('color 를 지정하면 상태 색상 클래스가 붙지 않고 지정 색이 유지된다', () => {
153
+ // Given/When: color 를 지정해 렌더하면
154
+ const view = mountInputBase({
155
+ leadingElement: {
156
+ type: 'icon',
157
+ icon: SearchLg,
158
+ color: 'blue500'
159
+ }
160
+ });
161
+ // Then: 상태 규칙에서 제외되고 지정한 색이 그대로 남는다
162
+ const icon = leftIconOf(view.container);
163
+ expect(icon?.classList.contains('ncua-input__slot-icon')).toBe(false);
164
+ expect(icon?.getAttribute('color')).toBe(COLOR.blue500);
165
+ view.unmount();
166
+ });
167
+ it('slot.className 을 함께 주어도 상태 색상 클래스가 유지된다', () => {
168
+ // Given/When: className 을 추가로 넘기면
169
+ const view = mountInputBase({
170
+ leadingElement: {
171
+ type: 'icon',
172
+ icon: SearchLg,
173
+ className: 'my-icon'
174
+ }
175
+ });
176
+ // Then: 두 클래스가 모두 붙는다
177
+ const icon = leftIconOf(view.container);
178
+ expect(icon?.classList.contains('ncua-input__slot-icon')).toBe(true);
179
+ expect(icon?.classList.contains('my-icon')).toBe(true);
180
+ view.unmount();
181
+ });
182
+ });
133
183
  describe('InputBase — has-value 상태 클래스', () => {
134
184
  const typeInto = (container, text) => {
135
185
  const input = container.querySelector('input');
@@ -178,4 +228,70 @@ describe('InputBase — has-value 상태 클래스', () => {
178
228
  expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(true);
179
229
  view.unmount();
180
230
  });
231
+ });
232
+ describe('InputBase — 텍스트 슬롯', () => {
233
+ it('leadingElement 텍스트는 leading 클래스와 wrap 클래스가 붙는다', () => {
234
+ const {
235
+ container,
236
+ unmount
237
+ } = mountInputBase({
238
+ leadingElement: {
239
+ type: 'text',
240
+ text: 'https://'
241
+ }
242
+ });
243
+ const text = container.querySelector('.ncua-input__leading-text');
244
+ expect(text?.textContent).toBe('https://');
245
+ expect(container.querySelector('.ncua-input__leading-text-wrap')).not.toBeNull();
246
+ unmount();
247
+ });
248
+ it('trailingElement 텍스트는 trailing 클래스와 wrap 클래스가 붙는다', () => {
249
+ const {
250
+ container,
251
+ unmount
252
+ } = mountInputBase({
253
+ trailingElement: {
254
+ type: 'text',
255
+ text: 'px'
256
+ }
257
+ });
258
+ const text = container.querySelector('.ncua-input__trailing-text');
259
+ expect(text?.textContent).toBe('px');
260
+ expect(container.querySelector('.ncua-input__trailing-text-wrap')).not.toBeNull();
261
+ // leading 클래스가 섞이면 모서리·테두리 방향이 반대가 된다
262
+ expect(container.querySelector('.ncua-input__leading-text')).toBeNull();
263
+ unmount();
264
+ });
265
+ it('trailingElement 텍스트는 입력 필드 뒤에 온다', () => {
266
+ const {
267
+ container,
268
+ unmount
269
+ } = mountInputBase({
270
+ trailingElement: {
271
+ type: 'text',
272
+ text: 'px'
273
+ }
274
+ });
275
+ const content = container.querySelector('.ncua-input__content');
276
+ const children = Array.from(content?.children ?? []);
277
+ const fieldIndex = children.findIndex(el => el.classList.contains('ncua-input__field'));
278
+ const textIndex = children.findIndex(el => el.classList.contains('ncua-input__trailing-text'));
279
+ expect(fieldIndex).toBeGreaterThanOrEqual(0);
280
+ expect(textIndex).toBeGreaterThan(fieldIndex);
281
+ unmount();
282
+ });
283
+ it('사이즈 modifier 가 함께 붙는다', () => {
284
+ const {
285
+ container,
286
+ unmount
287
+ } = mountInputBase({
288
+ size: 'sm',
289
+ trailingElement: {
290
+ type: 'text',
291
+ text: 'px'
292
+ }
293
+ });
294
+ expect(container.querySelector('.ncua-input__trailing-text--sm')).not.toBeNull();
295
+ unmount();
296
+ });
181
297
  });
@@ -26,9 +26,9 @@ export const PasswordInput = /*#__PURE__*/forwardRef((_ref, ref) => {
26
26
  type: isVisible ? 'text' : 'password',
27
27
  leadingElement: {
28
28
  type: 'icon',
29
- icon: Lock01,
30
- // 색은 CSS가 결정한다 여기서 props.value로 판정하면 uncontrolled Input에서 영원히 빈 값 취급된다
31
- className: 'ncua-input__password-lock-icon'
29
+ icon: Lock01
30
+ // color 넘기지 않아 슬롯 아이콘 공통 규칙(상태별 색)을 그대로 따른다.
31
+ // 여기서 props.value 로 판정하면 uncontrolled Input 에서 영원히 빈 값 취급된다.
32
32
  },
33
33
  trailingElement: {
34
34
  type: 'custom',
@@ -0,0 +1,56 @@
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() {
10
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
+ const container = document.createElement('div');
12
+ document.body.appendChild(container);
13
+ const root = createRoot(container);
14
+ act(() => {
15
+ root.render(/*#__PURE__*/createElement(PasswordInput, props));
16
+ });
17
+ const unmount = () => {
18
+ act(() => {
19
+ root.unmount();
20
+ });
21
+ container.remove();
22
+ };
23
+ return {
24
+ container,
25
+ unmount
26
+ };
27
+ }
28
+ describe('PasswordInput — 자물쇠 아이콘 색상', () => {
29
+ // 자물쇠 색은 CSS 가 결정한다. 인라인 color 를 넘기면 상태 규칙이 무시되므로,
30
+ // "인라인 색이 없고 슬롯 아이콘 공통 클래스를 탄다" 는 것이 색상 반영의 전제다.
31
+ it('자물쇠에 인라인 색을 넘기지 않고 슬롯 아이콘 공통 클래스를 탄다', () => {
32
+ // Given/When: 기본 상태로 렌더하면
33
+ const view = mountPasswordInput();
34
+ // Then: 상태 규칙을 타는 클래스가 붙고 인라인 색은 없다
35
+ const lockIcon = view.container.querySelector('.ncua-input__left-icon');
36
+ expect(lockIcon).not.toBeNull();
37
+ expect(lockIcon?.classList.contains('ncua-input__slot-icon')).toBe(true);
38
+ expect(lockIcon?.hasAttribute('color')).toBe(false);
39
+ view.unmount();
40
+ });
41
+ // 값이 있는 채로 비활성화되면 has-value 가 살아 있어 자물쇠가 진하게 남던 문제
42
+ it('값이 있는 채로 disabled 여도 자물쇠가 상태 규칙 대상으로 남는다', () => {
43
+ // Given/When: 값이 있는 비활성화 상태로 렌더하면
44
+ const view = mountPasswordInput({
45
+ value: 'secret',
46
+ disabled: true,
47
+ onChange: vi.fn()
48
+ });
49
+ // Then: 루트에 is-disabled 와 has-value 가 함께 붙고, 자물쇠는 공통 클래스를 유지한다
50
+ const root = view.container.querySelector('.ncua-input');
51
+ expect(root?.classList.contains('is-disabled')).toBe(true);
52
+ expect(root?.classList.contains('has-value')).toBe(true);
53
+ expect(view.container.querySelector('.ncua-input__left-icon')?.classList.contains('ncua-input__slot-icon')).toBe(true);
54
+ view.unmount();
55
+ });
56
+ });