@ncds/ui-admin 1.8.20 → 1.8.21-alpha.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.
- package/dist/cjs/src/components/feedback-and-status/badge/Badge.js +1 -1
- package/dist/cjs/src/components/forms-and-input/input-base/InputBase.js +31 -25
- package/dist/cjs/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +112 -0
- package/dist/cjs/src/components/forms-and-input/password-input/PasswordInput.js +2 -1
- package/dist/cjs/src/components/index.js +11 -0
- package/dist/cjs/src/components/layout/ncua-scope/NcuaScope.js +73 -0
- package/dist/cjs/src/components/layout/ncua-scope/index.js +16 -0
- package/dist/cjs/src/generated/scoped-css.js +9 -0
- package/dist/esm/src/components/feedback-and-status/badge/Badge.js +1 -1
- package/dist/esm/src/components/forms-and-input/input-base/InputBase.js +31 -25
- package/dist/esm/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +112 -0
- package/dist/esm/src/components/forms-and-input/password-input/PasswordInput.js +2 -1
- package/dist/esm/src/components/index.js +1 -0
- package/dist/esm/src/components/layout/ncua-scope/NcuaScope.js +67 -0
- package/dist/esm/src/components/layout/ncua-scope/index.js +1 -0
- package/dist/esm/src/generated/scoped-css.js +3 -0
- package/dist/temp/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
- package/dist/temp/src/components/feedback-and-status/badge/Badge.js +1 -1
- package/dist/temp/src/components/forms-and-input/input-base/InputBase.js +25 -20
- package/dist/temp/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +95 -0
- package/dist/temp/src/components/forms-and-input/password-input/PasswordInput.js +2 -1
- package/dist/temp/src/components/index.d.ts +1 -0
- package/dist/temp/src/components/index.js +1 -0
- package/dist/temp/src/components/layout/ncua-scope/NcuaScope.d.ts +32 -0
- package/dist/temp/src/components/layout/ncua-scope/NcuaScope.js +47 -0
- package/dist/temp/src/components/layout/ncua-scope/index.d.ts +1 -0
- package/dist/temp/src/components/layout/ncua-scope/index.js +1 -0
- package/dist/temp/src/generated/scoped-css.d.ts +1 -0
- package/dist/temp/src/generated/scoped-css.js +3 -0
- package/dist/types/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/layout/ncua-scope/NcuaScope.d.ts +32 -0
- package/dist/types/src/components/layout/ncua-scope/index.d.ts +1 -0
- package/dist/types/src/generated/scoped-css.d.ts +1 -0
- package/dist/ui-admin/assets/styles/style.css +22 -26
- package/dist/ui-admin/assets/styles/style.scoped.css +8350 -0
- package/package.json +13 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
+
import { SearchLg } from '@ncds/ui-admin-icon';
|
|
2
3
|
import { createElement } from 'react';
|
|
3
4
|
import { createRoot } from 'react-dom/client';
|
|
4
5
|
import { act } from 'react-dom/test-utils';
|
|
@@ -66,4 +67,115 @@ describe('InputBase — clearText prop DOM 누출', () => {
|
|
|
66
67
|
expect(view.container.querySelector('.ncua-input__clear')).toBeNull();
|
|
67
68
|
view.unmount();
|
|
68
69
|
});
|
|
70
|
+
});
|
|
71
|
+
describe('InputBase — 아이콘 사이즈', () => {
|
|
72
|
+
const iconSizeOf = (container, selector) => {
|
|
73
|
+
const svg = container.querySelector(selector);
|
|
74
|
+
return {
|
|
75
|
+
width: svg?.getAttribute('width'),
|
|
76
|
+
height: svg?.getAttribute('height')
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
// 슬롯 아이콘과 상태 아이콘은 같은 크기를 쓴다 — 과거 상태 아이콘만 sm=16으로 어긋나 있었다
|
|
80
|
+
it.each([['xs', '14'], ['sm', '20']])('size=%s 일 때 슬롯 아이콘과 상태 아이콘이 모두 %spx로 렌더된다', (size, expected) => {
|
|
81
|
+
// Given/When: 슬롯 아이콘과 clear 버튼, destructive 상태를 함께 렌더하면
|
|
82
|
+
const view = mountInputBase({
|
|
83
|
+
size,
|
|
84
|
+
destructive: true,
|
|
85
|
+
clearText: true,
|
|
86
|
+
onClearText: vi.fn(),
|
|
87
|
+
leadingElement: {
|
|
88
|
+
type: 'icon',
|
|
89
|
+
icon: SearchLg
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// Then: 슬롯·clear·destructive 아이콘의 크기가 서로 어긋나지 않는다
|
|
93
|
+
const expectedSize = {
|
|
94
|
+
width: expected,
|
|
95
|
+
height: expected
|
|
96
|
+
};
|
|
97
|
+
expect(iconSizeOf(view.container, '.ncua-input__left-icon')).toEqual(expectedSize);
|
|
98
|
+
expect(iconSizeOf(view.container, '.ncua-input__clear-icon')).toEqual(expectedSize);
|
|
99
|
+
expect(iconSizeOf(view.container, '.ncua-input__destructive-icon')).toEqual(expectedSize);
|
|
100
|
+
view.unmount();
|
|
101
|
+
});
|
|
102
|
+
it.each([['xs', '14'], ['sm', '20']])('size=%s 일 때 validation 아이콘도 %spx로 렌더된다', (size, expected) => {
|
|
103
|
+
// Given/When: validation 상태로 렌더하면
|
|
104
|
+
const view = mountInputBase({
|
|
105
|
+
size,
|
|
106
|
+
validation: true
|
|
107
|
+
});
|
|
108
|
+
// Then: 다른 아이콘과 같은 크기다
|
|
109
|
+
expect(iconSizeOf(view.container, '.ncua-input__validation-icon')).toEqual({
|
|
110
|
+
width: expected,
|
|
111
|
+
height: expected
|
|
112
|
+
});
|
|
113
|
+
view.unmount();
|
|
114
|
+
});
|
|
115
|
+
it('slot.size를 직접 주면 기본 사이즈보다 우선한다', () => {
|
|
116
|
+
// Given/When: 슬롯에 size를 명시해 렌더하면
|
|
117
|
+
const view = mountInputBase({
|
|
118
|
+
size: 'xs',
|
|
119
|
+
leadingElement: {
|
|
120
|
+
type: 'icon',
|
|
121
|
+
icon: SearchLg,
|
|
122
|
+
size: 24
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// Then: 기본값(14)이 아니라 명시한 값이 적용된다
|
|
126
|
+
expect(iconSizeOf(view.container, '.ncua-input__left-icon')).toEqual({
|
|
127
|
+
width: '24',
|
|
128
|
+
height: '24'
|
|
129
|
+
});
|
|
130
|
+
view.unmount();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('InputBase — has-value 상태 클래스', () => {
|
|
134
|
+
const typeInto = (container, text) => {
|
|
135
|
+
const input = container.querySelector('input');
|
|
136
|
+
if (!input) throw new Error('input이 렌더되지 않았습니다');
|
|
137
|
+
act(() => {
|
|
138
|
+
input.value = text;
|
|
139
|
+
input.dispatchEvent(new Event('input', {
|
|
140
|
+
bubbles: true
|
|
141
|
+
}));
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
it('값이 비어 있으면 has-value가 붙지 않는다', () => {
|
|
145
|
+
// Given/When: 빈 상태로 렌더하면
|
|
146
|
+
const view = mountInputBase();
|
|
147
|
+
// Then: 루트에 has-value가 없다
|
|
148
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(false);
|
|
149
|
+
view.unmount();
|
|
150
|
+
});
|
|
151
|
+
// props.value 로 판정하면 uncontrolled 에서 영원히 빈 값으로 보인다 — 자물쇠 아이콘 색상이 반영되지 않던 원인
|
|
152
|
+
it('uncontrolled Input에 입력하면 has-value가 붙는다', () => {
|
|
153
|
+
// Given: value를 넘기지 않은 uncontrolled 상태에서
|
|
154
|
+
const view = mountInputBase();
|
|
155
|
+
// When: 실제로 입력하면
|
|
156
|
+
typeInto(view.container, 'hello');
|
|
157
|
+
// Then: has-value가 붙는다
|
|
158
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(true);
|
|
159
|
+
view.unmount();
|
|
160
|
+
});
|
|
161
|
+
it('입력값을 지우면 has-value가 떨어진다', () => {
|
|
162
|
+
// Given: 값이 있는 상태에서
|
|
163
|
+
const view = mountInputBase();
|
|
164
|
+
typeInto(view.container, 'hello');
|
|
165
|
+
// When: 값을 비우면
|
|
166
|
+
typeInto(view.container, '');
|
|
167
|
+
// Then: has-value가 사라진다
|
|
168
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(false);
|
|
169
|
+
view.unmount();
|
|
170
|
+
});
|
|
171
|
+
it('controlled Input은 value prop만으로도 has-value가 붙는다', () => {
|
|
172
|
+
// Given/When: value를 직접 넘겨 렌더하면 (input 이벤트 없이)
|
|
173
|
+
const view = mountInputBase({
|
|
174
|
+
value: 'preset',
|
|
175
|
+
onChange: vi.fn()
|
|
176
|
+
});
|
|
177
|
+
// Then: has-value가 붙는다
|
|
178
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(true);
|
|
179
|
+
view.unmount();
|
|
180
|
+
});
|
|
69
181
|
});
|
|
@@ -27,7 +27,8 @@ export const PasswordInput = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
27
27
|
leadingElement: {
|
|
28
28
|
type: 'icon',
|
|
29
29
|
icon: Lock01,
|
|
30
|
-
|
|
30
|
+
// 색은 CSS가 결정한다 — 여기서 props.value로 판정하면 uncontrolled Input에서 영원히 빈 값 취급된다
|
|
31
|
+
className: 'ncua-input__password-lock-icon'
|
|
31
32
|
},
|
|
32
33
|
trailingElement: {
|
|
33
34
|
type: 'custom',
|
|
@@ -39,6 +39,7 @@ export * from './image-and-icons/featured-icon';
|
|
|
39
39
|
export * from './layout/block-container';
|
|
40
40
|
export * from './layout/block-header';
|
|
41
41
|
export * from './layout/divider';
|
|
42
|
+
export * from './layout/ncua-scope';
|
|
42
43
|
export * from './layout/page-title';
|
|
43
44
|
// Navigation
|
|
44
45
|
export * from './navigation/bread-crumb';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { createContext, forwardRef, version as reactVersion, useContext } from 'react';
|
|
6
|
+
import { NCUA_SCOPED_CSS } from '../../../generated/scoped-css';
|
|
7
|
+
// 조상에 NcuaScope 가 이미 있으면 스타일을 다시 심지 않는다 (중첩 대응).
|
|
8
|
+
const NcuaStyleMountedContext = /*#__PURE__*/createContext(false);
|
|
9
|
+
// React 19 는 <style> 에 href·precedence 가 함께 있으면 <head> 로 올리고 href 로 중복을
|
|
10
|
+
// 제거한다. 18 에는 그 기능도, 두 prop 의 타입 정의도 없어 Context 로 중첩만 막고
|
|
11
|
+
// 타입은 우회한다.
|
|
12
|
+
const STYLE_HOISTING_MIN_REACT_MAJOR = 19;
|
|
13
|
+
const DECIMAL_RADIX = 10;
|
|
14
|
+
const SUPPORTS_STYLE_HOISTING = Number.parseInt(reactVersion, DECIMAL_RADIX) >= STYLE_HOISTING_MIN_REACT_MAJOR;
|
|
15
|
+
const STYLE_KEY = 'ncua-scoped';
|
|
16
|
+
const STYLE_HOISTING_PROPS = {
|
|
17
|
+
href: STYLE_KEY,
|
|
18
|
+
precedence: 'default'
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* NCUA 스타일을 이 엘리먼트 하위로 한정하는 경계.
|
|
22
|
+
*
|
|
23
|
+
* 다른 디자인 시스템을 전역 적용한 사용처에서 NCUA 컴포넌트를 이걸로 감싼다.
|
|
24
|
+
* 스타일을 직접 들고 있으므로 **CSS 파일을 따로 import 하지 않는다.**
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { NcuaScope, Button } from '@ncds/ui-admin';
|
|
28
|
+
*
|
|
29
|
+
* <NcuaScope>
|
|
30
|
+
* <Button label="신청하기" hierarchy="primary" size="md" />
|
|
31
|
+
* </NcuaScope>
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* `document.body` 로 portal 되는 컴포넌트(Modal · Tooltip · Dropdown · SelectBox ·
|
|
35
|
+
* Notification)는 이 경계 밖에 놓이지만, 스코프 스타일시트가 그 루트 클래스들을 함께
|
|
36
|
+
* 지정하므로 토큰을 받는다 (`base/_scope.scss` 의 `$roots`). portal 목적지는 바뀌지
|
|
37
|
+
* 않으므로 어드민에서의 기존 동작과 같다.
|
|
38
|
+
*
|
|
39
|
+
* 어드민처럼 `style.css` 를 전역 적용하는 사용처는 이 컴포넌트가 필요 없다.
|
|
40
|
+
*
|
|
41
|
+
* 중첩해서 써도 스타일은 한 번만 들어간다. React 19 에서는 형제로 여러 개를 써도
|
|
42
|
+
* href 기준으로 중복이 제거된다. React 18 에서는 형제마다 `<style>` 이 하나씩 생기므로,
|
|
43
|
+
* 스코프가 여러 곳에 필요하면 공통 조상 한 곳에서 감싸는 편이 낫다.
|
|
44
|
+
*/
|
|
45
|
+
export const NcuaScope = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
46
|
+
let {
|
|
47
|
+
className,
|
|
48
|
+
children
|
|
49
|
+
} = _ref;
|
|
50
|
+
const styleAlreadyMounted = useContext(NcuaStyleMountedContext);
|
|
51
|
+
const shouldRenderStyle = SUPPORTS_STYLE_HOISTING || !styleAlreadyMounted;
|
|
52
|
+
return _jsxs(NcuaStyleMountedContext.Provider, {
|
|
53
|
+
value: true,
|
|
54
|
+
children: [shouldRenderStyle && (SUPPORTS_STYLE_HOISTING ? _jsx("style", {
|
|
55
|
+
...STYLE_HOISTING_PROPS,
|
|
56
|
+
children: NCUA_SCOPED_CSS
|
|
57
|
+
}) : _jsx("style", {
|
|
58
|
+
"data-ncua-scope": STYLE_KEY,
|
|
59
|
+
children: NCUA_SCOPED_CSS
|
|
60
|
+
})), _jsx("div", {
|
|
61
|
+
ref: ref,
|
|
62
|
+
className: classnames('ncua-scope', className),
|
|
63
|
+
children: children
|
|
64
|
+
})]
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
NcuaScope.displayName = 'NcuaScope';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NcuaScope';
|