@teamturing/react-kit 2.13.0 → 2.14.0

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.
@@ -0,0 +1,273 @@
1
+ import { useCallback, Fragment } from 'react';
2
+ import SvgChevronLeft from '../../packages/icons/esm/ChevronLeft.js';
3
+ import SvgChevronRight from '../../packages/icons/esm/ChevronRight.js';
4
+ import { noop } from '../../packages/utils/esm/noop.js';
5
+ import styled, { css } from 'styled-components';
6
+ import '../../node_modules/styled-system/dist/index.esm.js';
7
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
8
+ import { sx } from '../../utils/styled-system/index.js';
9
+ import UnstyledButton from '../_UnstyledButton.js';
10
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
11
+ import { variant } from '../../node_modules/@styled-system/variant/dist/index.esm.js';
12
+
13
+ const Pagination = ({
14
+ pages: propPages,
15
+ currentPageIndex,
16
+ aroundPageCount = 1,
17
+ edgePageCount = 1,
18
+ type = 'default',
19
+ sx,
20
+ onPageClick = noop,
21
+ onPreviousClick = noop,
22
+ onNextClick = noop,
23
+ renderPage = (page, i) => /*#__PURE__*/jsxRuntimeExports.jsx(PaginationPage, {
24
+ onClick: () => onPageClick(page, i),
25
+ selected: i === currentPageIndex,
26
+ children: page.label
27
+ }),
28
+ renderPageWrapper = (children, {
29
+ label
30
+ }, i) => /*#__PURE__*/jsxRuntimeExports.jsx(Fragment, {
31
+ children: children
32
+ }, [label, i].join('-')),
33
+ renderPreviousPageDirection = ({
34
+ previousPageDirectionProps
35
+ }) => /*#__PURE__*/jsxRuntimeExports.jsxs(PaginationPageDirection, {
36
+ ...previousPageDirectionProps,
37
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(SvgChevronLeft, {}), "\uC774\uC804"]
38
+ }),
39
+ renderNextPageDirection = ({
40
+ nextPageDirectionProps
41
+ }) => /*#__PURE__*/jsxRuntimeExports.jsxs(PaginationPageDirection, {
42
+ ...nextPageDirectionProps,
43
+ children: ["\uB2E4\uC74C", /*#__PURE__*/jsxRuntimeExports.jsx(SvgChevronRight, {})]
44
+ }),
45
+ renderTruncationIndicator = () => /*#__PURE__*/jsxRuntimeExports.jsx(PaginationTruncationIndicator, {
46
+ children: "\u2026"
47
+ })
48
+ }) => {
49
+ const CURRENT_PAGE_COUNT = 1;
50
+ const totalVisiblePageCount = CURRENT_PAGE_COUNT + 2 * aroundPageCount + 2 * edgePageCount;
51
+ const pages = propPages.map((page, i) => ({
52
+ page,
53
+ originalIndex: i
54
+ }));
55
+ const totalPageCount = propPages.length;
56
+ const isCurrentPageCloseToBeginEdge = currentPageIndex < edgePageCount + aroundPageCount + CURRENT_PAGE_COUNT;
57
+ const isCurrentPageCloseToEndEdge = totalPageCount - (edgePageCount + aroundPageCount + CURRENT_PAGE_COUNT) < currentPageIndex + 1;
58
+ const isTruncationNeeded = totalVisiblePageCount < totalPageCount;
59
+ const renderPaginationPage = useCallback((page, i) => renderPageWrapper(renderPage(page, i), page, i), [currentPageIndex]);
60
+ return /*#__PURE__*/jsxRuntimeExports.jsxs(BasePagination, {
61
+ type: type,
62
+ sx: sx,
63
+ children: [renderPreviousPageDirection({
64
+ previousPageDirectionProps: {
65
+ onClick: () => onPreviousClick(currentPageIndex),
66
+ disabled: currentPageIndex === 0
67
+ }
68
+ }), !isTruncationNeeded ? pages.map(({
69
+ page,
70
+ originalIndex
71
+ }) => renderPaginationPage(page, originalIndex)) : isTruncationNeeded && isCurrentPageCloseToBeginEdge ? [pages.slice(0, edgePageCount + aroundPageCount * 2 + CURRENT_PAGE_COUNT).map(({
72
+ page,
73
+ originalIndex
74
+ }) => renderPaginationPage(page, originalIndex)), /*#__PURE__*/jsxRuntimeExports.jsx(Fragment, {
75
+ children: renderTruncationIndicator()
76
+ }, 'end_truncation_indicator'), pages.slice(edgePageCount * -1).map(({
77
+ page,
78
+ originalIndex
79
+ }) => renderPaginationPage(page, originalIndex))] : isTruncationNeeded && isCurrentPageCloseToEndEdge ? [pages.slice(0, edgePageCount).map(({
80
+ page,
81
+ originalIndex
82
+ }) => renderPaginationPage(page, originalIndex)), /*#__PURE__*/jsxRuntimeExports.jsx(Fragment, {
83
+ children: renderTruncationIndicator()
84
+ }, 'begin_truncation_indicator'), pages.slice(totalPageCount - (edgePageCount + aroundPageCount * 2 + CURRENT_PAGE_COUNT)).map(({
85
+ page,
86
+ originalIndex
87
+ }) => renderPaginationPage(page, originalIndex))] : [pages.slice(0, edgePageCount).map(({
88
+ page,
89
+ originalIndex
90
+ }) => renderPaginationPage(page, originalIndex)), /*#__PURE__*/jsxRuntimeExports.jsx(Fragment, {
91
+ children: renderTruncationIndicator()
92
+ }, 'begin_truncation_indicator'), pages.slice(currentPageIndex - aroundPageCount, currentPageIndex + aroundPageCount + CURRENT_PAGE_COUNT).map(({
93
+ page,
94
+ originalIndex
95
+ }) => renderPaginationPage(page, originalIndex)), /*#__PURE__*/jsxRuntimeExports.jsx(Fragment, {
96
+ children: renderTruncationIndicator()
97
+ }, 'end_truncation_indicator'), pages.slice(edgePageCount * -1).map(({
98
+ page,
99
+ originalIndex
100
+ }) => renderPaginationPage(page, originalIndex))], renderNextPageDirection({
101
+ nextPageDirectionProps: {
102
+ onClick: () => onNextClick(currentPageIndex),
103
+ disabled: currentPageIndex === totalPageCount - 1
104
+ }
105
+ })]
106
+ });
107
+ };
108
+ const BasePagination = styled.nav`
109
+ display: flex;
110
+ align-items: center;
111
+ justify-content: center;
112
+ flex-wrap: nowrap;
113
+ column-gap: ${({
114
+ theme
115
+ }) => forcePixelValue(theme.space[1])};
116
+
117
+ ${variant({
118
+ prop: 'type',
119
+ variants: {
120
+ default: {},
121
+ simple: {
122
+ '& > *:not(:first-child):not(:last-child)': {
123
+ display: 'none !important'
124
+ }
125
+ }
126
+ }
127
+ })}
128
+ ${sx}
129
+ `;
130
+ const PaginationPage = styled(UnstyledButton)`
131
+ transition: background-color 100ms;
132
+
133
+ height: ${forcePixelValue(32)};
134
+ min-width: ${forcePixelValue(32)};
135
+
136
+ border-radius: ${({
137
+ theme
138
+ }) => forcePixelValue(theme.radii.xs)};
139
+ padding: ${({
140
+ theme
141
+ }) => `${forcePixelValue(theme.space[0])} ${forcePixelValue(theme.space[3])}`};
142
+ background-color: ${({
143
+ theme
144
+ }) => theme.colors['bg/neutral/subtler']};
145
+
146
+ font-size: ${({
147
+ theme
148
+ }) => forcePixelValue(theme.fontSizes.xs)};
149
+ font-weight: ${({
150
+ theme
151
+ }) => theme.fontWeights.regular};
152
+ line-height: ${({
153
+ theme
154
+ }) => theme.lineHeights[2]};
155
+ color: ${({
156
+ theme
157
+ }) => theme.colors['text/neutral']};
158
+
159
+ ${({
160
+ selected
161
+ }) => selected ? css`
162
+ background-color: ${({
163
+ theme
164
+ }) => theme.colors['bg/neutral/bolder']};
165
+ color: ${({
166
+ theme
167
+ }) => theme.colors['text/inverse']};
168
+ ` : css`
169
+ &:hover {
170
+ background-color: ${({
171
+ theme
172
+ }) => theme.colors['bg/neutral/subtler/hovered']};
173
+ }
174
+ `}
175
+ `;
176
+ const PaginationPageDirection = styled(UnstyledButton)`
177
+ transition: background-color 100ms;
178
+
179
+ display: inline-flex;
180
+ align-items: center;
181
+ flex-wrap: nowrap;
182
+ column-gap: ${({
183
+ theme
184
+ }) => forcePixelValue(theme.space[1])};
185
+
186
+ height: ${forcePixelValue(32)};
187
+ min-width: ${forcePixelValue(32)};
188
+
189
+ border-radius: ${({
190
+ theme
191
+ }) => forcePixelValue(theme.radii.xs)};
192
+ padding: ${({
193
+ theme
194
+ }) => `${forcePixelValue(theme.space[0])} ${forcePixelValue(theme.space[3])}`};
195
+ background-color: ${({
196
+ theme
197
+ }) => theme.colors['bg/neutral/subtler']};
198
+
199
+ font-size: ${({
200
+ theme
201
+ }) => forcePixelValue(theme.fontSizes.xs)};
202
+ font-weight: ${({
203
+ theme
204
+ }) => theme.fontWeights.regular};
205
+ line-height: ${({
206
+ theme
207
+ }) => theme.lineHeights[2]};
208
+ color: ${({
209
+ theme
210
+ }) => theme.colors['text/neutral']};
211
+
212
+ & svg {
213
+ color: ${({
214
+ theme
215
+ }) => theme.colors['icon/accent/gray']};
216
+ width: ${forcePixelValue(16)};
217
+ height: ${forcePixelValue(16)};
218
+ }
219
+
220
+ &:hover:not(:disabled) {
221
+ background-color: ${({
222
+ theme
223
+ }) => theme.colors['bg/neutral/subtler/hovered']};
224
+ }
225
+ &:disabled {
226
+ cursor: not-allowed;
227
+ color: ${({
228
+ theme
229
+ }) => theme.colors['text/disabled']};
230
+ & > svg {
231
+ color: ${({
232
+ theme
233
+ }) => theme.colors['icon/disabled']};
234
+ }
235
+ }
236
+ `;
237
+ const PaginationTruncationIndicator = styled.div`
238
+ min-width: ${forcePixelValue(32)};
239
+
240
+ border-radius: ${({
241
+ theme
242
+ }) => forcePixelValue(theme.radii.xs)};
243
+ padding: ${({
244
+ theme
245
+ }) => `${forcePixelValue(theme.space[0])} ${forcePixelValue(theme.space[3])}`};
246
+ background-color: ${({
247
+ theme
248
+ }) => theme.colors['bg/neutral/subtler']};
249
+
250
+ font-size: ${({
251
+ theme
252
+ }) => forcePixelValue(theme.fontSizes.xs)};
253
+ font-weight: ${({
254
+ theme
255
+ }) => theme.fontWeights.regular};
256
+ line-height: ${({
257
+ theme
258
+ }) => theme.lineHeights[2]};
259
+ color: ${({
260
+ theme
261
+ }) => theme.colors['text/neutral']};
262
+
263
+ pointer-events: none;
264
+
265
+ ${sx}
266
+ `;
267
+ var index = Object.assign(Pagination, {
268
+ Page: PaginationPage,
269
+ PageDirection: PaginationPageDirection,
270
+ TruncationIndicator: PaginationTruncationIndicator
271
+ });
272
+
273
+ export { index as default };
@@ -0,0 +1,129 @@
1
+ import { forwardRef } from 'react';
2
+ import SvgClose from '../../packages/icons/esm/Close.js';
3
+ import { r as reactIsExports } from '../../node_modules/react-is/index.js';
4
+ import styled from 'styled-components';
5
+ import '../../node_modules/styled-system/dist/index.esm.js';
6
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
7
+ import { isNullable } from '../../utils/isNullable.js';
8
+ import { sx } from '../../utils/styled-system/index.js';
9
+ import UnstyledButton from '../_UnstyledButton.js';
10
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
11
+ import { variant } from '../../node_modules/@styled-system/variant/dist/index.esm.js';
12
+
13
+ const Pill = ({
14
+ text,
15
+ size = 'm',
16
+ variant = 'secondary',
17
+ leadingVisual: LeadingVisual,
18
+ onRemove,
19
+ ...props
20
+ }, ref) => /*#__PURE__*/jsxRuntimeExports.jsxs(BasePill, {
21
+ ref: ref,
22
+ size: size,
23
+ variant: variant,
24
+ hasLeadingVisual: !isNullable(LeadingVisual),
25
+ hasRemoveButton: !isNullable(onRemove),
26
+ ...props,
27
+ children: [typeof LeadingVisual !== 'string' && reactIsExports.isValidElementType(LeadingVisual) ? /*#__PURE__*/jsxRuntimeExports.jsx(LeadingVisual, {}) : LeadingVisual, text, onRemove ? /*#__PURE__*/jsxRuntimeExports.jsx(UnstyledButton, {
28
+ type: 'button',
29
+ onClick: onRemove,
30
+ "aria-label": 'Remove Pill',
31
+ children: /*#__PURE__*/jsxRuntimeExports.jsx(SvgClose, {})
32
+ }) : null]
33
+ });
34
+ const BasePill = styled.span`
35
+ display: inline-flex;
36
+ align-items: center;
37
+ border-radius: ${({
38
+ theme
39
+ }) => forcePixelValue(theme.radii.xxs)};
40
+
41
+ & > button {
42
+ display: flex;
43
+ transition: background-color 100ms;
44
+ border-radius: ${({
45
+ theme
46
+ }) => forcePixelValue(theme.radii.full)};
47
+ }
48
+
49
+ ${({
50
+ theme,
51
+ hasLeadingVisual,
52
+ hasRemoveButton
53
+ }) => variant({
54
+ prop: 'size',
55
+ variants: {
56
+ l: {
57
+ 'pl': hasLeadingVisual || hasRemoveButton ? 2 : 3,
58
+ 'pr': hasRemoveButton ? 0.5 : hasLeadingVisual ? 2 : 3,
59
+ 'py': 1,
60
+ 'fontSize': theme.fontSizes.s,
61
+ 'fontWeight': theme.fontWeights.medium,
62
+ 'lineHeight': theme.lineHeights[2],
63
+ 'columnGap': 1,
64
+ '& svg': {
65
+ width: 16,
66
+ height: 16,
67
+ color: theme.colors['icon/primary']
68
+ },
69
+ '& button': {
70
+ p: 1
71
+ }
72
+ },
73
+ m: {
74
+ 'pl': hasLeadingVisual || hasRemoveButton ? 2 : 3,
75
+ 'pr': hasRemoveButton ? 1 : hasLeadingVisual ? 2 : 3,
76
+ 'py': 1,
77
+ 'fontSize': theme.fontSizes.xs,
78
+ 'fontWeight': theme.fontWeights.medium,
79
+ 'lineHeight': theme.lineHeights[2],
80
+ 'columnGap': 0.5,
81
+ '& svg': {
82
+ width: 16,
83
+ height: 16,
84
+ color: theme.colors['icon/primary']
85
+ },
86
+ '& button': {
87
+ p: 0.5
88
+ }
89
+ },
90
+ s: {
91
+ 'pl': 2,
92
+ 'pr': hasRemoveButton ? 1 : 2,
93
+ 'py': 0.5,
94
+ 'fontSize': theme.fontSizes.xxs,
95
+ 'fontWeight': theme.fontWeights.medium,
96
+ 'lineHeight': theme.lineHeights[2],
97
+ 'columnGap': 0.5,
98
+ '& svg': {
99
+ width: 12,
100
+ height: 12,
101
+ color: theme.colors['icon/primary']
102
+ },
103
+ '& button': {
104
+ p: 0.5
105
+ }
106
+ }
107
+ }
108
+ })}
109
+ ${({
110
+ theme
111
+ }) => variant({
112
+ prop: 'variant',
113
+ variants: {
114
+ secondary: {
115
+ 'color': theme.colors['text/primary'],
116
+ 'backgroundColor': theme.colors['bg/secondary'],
117
+ '& button': {
118
+ '&:hover': {
119
+ backgroundColor: theme.colors['bg/secondary/hovered']
120
+ }
121
+ }
122
+ }
123
+ }
124
+ })}
125
+ ${sx}
126
+ `;
127
+ var index = /*#__PURE__*/forwardRef(Pill);
128
+
129
+ export { index as default };
package/esm/index.js CHANGED
@@ -13,6 +13,8 @@ export { default as ItemList } from './core/ItemList/index.js';
13
13
  export { default as MotionView } from './core/MotionView/index.js';
14
14
  export { default as Overlay } from './core/Overlay/index.js';
15
15
  export { default as OverlayPopper } from './core/OverlayPopper/index.js';
16
+ export { default as Pagination } from './core/Pagination/index.js';
17
+ export { default as Pill } from './core/Pill/index.js';
16
18
  export { default as Space } from './core/Space/index.js';
17
19
  export { default as Spinner } from './core/Spinner/index.js';
18
20
  export { default as Stack } from './core/Stack/index.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 아무 행위도 하지 않는 함수입니다.
3
+ */
4
+ function noop() {}
5
+
6
+ export { noop };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -62,5 +62,5 @@
62
62
  "react-is": "^18.2.0",
63
63
  "styled-system": "^5.1.5"
64
64
  },
65
- "gitHead": "a7cd969d8f547c667184fc37ed1ccdfe1e159106"
65
+ "gitHead": "544bb0398781216f2425c6e23d897d0eaa029c95"
66
66
  }