@ncds/ui-admin 1.8.21-alpha.0 → 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.
- package/dist/cjs/src/components/forms-and-input/input-base/InputBase.js +42 -30
- package/dist/cjs/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +228 -0
- package/dist/cjs/src/components/forms-and-input/password-input/PasswordInput.js +3 -2
- package/dist/cjs/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js +59 -0
- 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/forms-and-input/input-base/InputBase.js +42 -30
- package/dist/esm/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +228 -0
- package/dist/esm/src/components/forms-and-input/password-input/PasswordInput.js +3 -2
- package/dist/esm/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js +56 -0
- 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/forms-and-input/input-base/InputBase.d.ts +1 -1
- package/dist/temp/src/components/forms-and-input/input-base/InputBase.js +33 -24
- package/dist/temp/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +174 -0
- package/dist/temp/src/components/forms-and-input/password-input/PasswordInput.js +2 -1
- package/dist/temp/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.d.ts +1 -0
- package/dist/temp/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js +48 -0
- 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/forms-and-input/input-base/InputBase.d.ts +1 -1
- package/dist/types/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.d.ts +1 -0
- 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 +51 -23
- package/dist/ui-admin/assets/styles/style.scoped.css +8383 -0
- package/package.json +13 -6
|
@@ -1,8 +1,10 @@
|
|
|
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';
|
|
5
6
|
import { describe, expect, it, vi } from 'vitest';
|
|
7
|
+
import { COLOR } from '../../../../../constant/color';
|
|
6
8
|
import { InputBase } from '../InputBase';
|
|
7
9
|
// React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
|
|
8
10
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
@@ -66,4 +68,230 @@ describe('InputBase — clearText prop DOM 누출', () => {
|
|
|
66
68
|
expect(view.container.querySelector('.ncua-input__clear')).toBeNull();
|
|
67
69
|
view.unmount();
|
|
68
70
|
});
|
|
71
|
+
});
|
|
72
|
+
describe('InputBase — 아이콘 사이즈', () => {
|
|
73
|
+
const iconSizeOf = (container, selector) => {
|
|
74
|
+
const svg = container.querySelector(selector);
|
|
75
|
+
return {
|
|
76
|
+
width: svg?.getAttribute('width'),
|
|
77
|
+
height: svg?.getAttribute('height')
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
// 슬롯 아이콘과 상태 아이콘은 같은 크기를 쓴다 — 과거 상태 아이콘만 sm=16으로 어긋나 있었다
|
|
81
|
+
it.each([['xs', '14'], ['sm', '20']])('size=%s 일 때 슬롯 아이콘과 상태 아이콘이 모두 %spx로 렌더된다', (size, expected) => {
|
|
82
|
+
// Given/When: 슬롯 아이콘과 clear 버튼, destructive 상태를 함께 렌더하면
|
|
83
|
+
const view = mountInputBase({
|
|
84
|
+
size,
|
|
85
|
+
destructive: true,
|
|
86
|
+
clearText: true,
|
|
87
|
+
onClearText: vi.fn(),
|
|
88
|
+
leadingElement: {
|
|
89
|
+
type: 'icon',
|
|
90
|
+
icon: SearchLg
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// Then: 슬롯·clear·destructive 아이콘의 크기가 서로 어긋나지 않는다
|
|
94
|
+
const expectedSize = {
|
|
95
|
+
width: expected,
|
|
96
|
+
height: expected
|
|
97
|
+
};
|
|
98
|
+
expect(iconSizeOf(view.container, '.ncua-input__left-icon')).toEqual(expectedSize);
|
|
99
|
+
expect(iconSizeOf(view.container, '.ncua-input__clear-icon')).toEqual(expectedSize);
|
|
100
|
+
expect(iconSizeOf(view.container, '.ncua-input__destructive-icon')).toEqual(expectedSize);
|
|
101
|
+
view.unmount();
|
|
102
|
+
});
|
|
103
|
+
it.each([['xs', '14'], ['sm', '20']])('size=%s 일 때 validation 아이콘도 %spx로 렌더된다', (size, expected) => {
|
|
104
|
+
// Given/When: validation 상태로 렌더하면
|
|
105
|
+
const view = mountInputBase({
|
|
106
|
+
size,
|
|
107
|
+
validation: true
|
|
108
|
+
});
|
|
109
|
+
// Then: 다른 아이콘과 같은 크기다
|
|
110
|
+
expect(iconSizeOf(view.container, '.ncua-input__validation-icon')).toEqual({
|
|
111
|
+
width: expected,
|
|
112
|
+
height: expected
|
|
113
|
+
});
|
|
114
|
+
view.unmount();
|
|
115
|
+
});
|
|
116
|
+
it('slot.size를 직접 주면 기본 사이즈보다 우선한다', () => {
|
|
117
|
+
// Given/When: 슬롯에 size를 명시해 렌더하면
|
|
118
|
+
const view = mountInputBase({
|
|
119
|
+
size: 'xs',
|
|
120
|
+
leadingElement: {
|
|
121
|
+
type: 'icon',
|
|
122
|
+
icon: SearchLg,
|
|
123
|
+
size: 24
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
// Then: 기본값(14)이 아니라 명시한 값이 적용된다
|
|
127
|
+
expect(iconSizeOf(view.container, '.ncua-input__left-icon')).toEqual({
|
|
128
|
+
width: '24',
|
|
129
|
+
height: '24'
|
|
130
|
+
});
|
|
131
|
+
view.unmount();
|
|
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
|
+
});
|
|
183
|
+
describe('InputBase — has-value 상태 클래스', () => {
|
|
184
|
+
const typeInto = (container, text) => {
|
|
185
|
+
const input = container.querySelector('input');
|
|
186
|
+
if (!input) throw new Error('input이 렌더되지 않았습니다');
|
|
187
|
+
act(() => {
|
|
188
|
+
input.value = text;
|
|
189
|
+
input.dispatchEvent(new Event('input', {
|
|
190
|
+
bubbles: true
|
|
191
|
+
}));
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
it('값이 비어 있으면 has-value가 붙지 않는다', () => {
|
|
195
|
+
// Given/When: 빈 상태로 렌더하면
|
|
196
|
+
const view = mountInputBase();
|
|
197
|
+
// Then: 루트에 has-value가 없다
|
|
198
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(false);
|
|
199
|
+
view.unmount();
|
|
200
|
+
});
|
|
201
|
+
// props.value 로 판정하면 uncontrolled 에서 영원히 빈 값으로 보인다 — 자물쇠 아이콘 색상이 반영되지 않던 원인
|
|
202
|
+
it('uncontrolled Input에 입력하면 has-value가 붙는다', () => {
|
|
203
|
+
// Given: value를 넘기지 않은 uncontrolled 상태에서
|
|
204
|
+
const view = mountInputBase();
|
|
205
|
+
// When: 실제로 입력하면
|
|
206
|
+
typeInto(view.container, 'hello');
|
|
207
|
+
// Then: has-value가 붙는다
|
|
208
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(true);
|
|
209
|
+
view.unmount();
|
|
210
|
+
});
|
|
211
|
+
it('입력값을 지우면 has-value가 떨어진다', () => {
|
|
212
|
+
// Given: 값이 있는 상태에서
|
|
213
|
+
const view = mountInputBase();
|
|
214
|
+
typeInto(view.container, 'hello');
|
|
215
|
+
// When: 값을 비우면
|
|
216
|
+
typeInto(view.container, '');
|
|
217
|
+
// Then: has-value가 사라진다
|
|
218
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(false);
|
|
219
|
+
view.unmount();
|
|
220
|
+
});
|
|
221
|
+
it('controlled Input은 value prop만으로도 has-value가 붙는다', () => {
|
|
222
|
+
// Given/When: value를 직접 넘겨 렌더하면 (input 이벤트 없이)
|
|
223
|
+
const view = mountInputBase({
|
|
224
|
+
value: 'preset',
|
|
225
|
+
onChange: vi.fn()
|
|
226
|
+
});
|
|
227
|
+
// Then: has-value가 붙는다
|
|
228
|
+
expect(view.container.querySelector('.ncua-input')?.classList.contains('has-value')).toBe(true);
|
|
229
|
+
view.unmount();
|
|
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
|
+
});
|
|
69
297
|
});
|
|
@@ -26,8 +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
|
-
color
|
|
29
|
+
icon: Lock01
|
|
30
|
+
// color 를 넘기지 않아 슬롯 아이콘 공통 규칙(상태별 색)을 그대로 따른다.
|
|
31
|
+
// 여기서 props.value 로 판정하면 uncontrolled Input 에서 영원히 빈 값 취급된다.
|
|
31
32
|
},
|
|
32
33
|
trailingElement: {
|
|
33
34
|
type: 'custom',
|
package/dist/esm/src/components/forms-and-input/password-input/__tests__/PasswordInput.test.js
ADDED
|
@@ -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
|
+
});
|
|
@@ -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';
|