@charcoal-ui/react-sandbox 3.2.0 → 3.3.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.
- package/dist/components/Carousel/index.story.d.ts +1 -1
- package/dist/components/CarouselButton/index.story.d.ts +1 -1
- package/dist/components/Pager/index.d.ts +2 -1
- package/dist/components/Pager/index.d.ts.map +1 -1
- package/dist/components/Pager/index.story.d.ts +8 -0
- package/dist/components/Pager/index.story.d.ts.map +1 -1
- package/dist/foundation/{contants.d.ts → constants.d.ts} +1 -1
- package/dist/foundation/constants.d.ts.map +1 -0
- package/dist/index.cjs.js +33 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +33 -18
- package/dist/index.esm.js.map +1 -1
- package/package.json +16 -15
- package/src/components/Carousel/index.tsx +7 -7
- package/src/components/Filter/index.story.tsx +1 -1
- package/src/components/Layout/index.tsx +1 -1
- package/src/components/MenuListItem/index.story.tsx +1 -1
- package/src/components/Pager/index.story.tsx +54 -6
- package/src/components/Pager/index.tsx +31 -11
- package/src/index.ts +1 -1
- package/dist/foundation/contants.d.ts.map +0 -1
- /package/src/foundation/{contants.ts → constants.ts} +0 -0
|
@@ -121,12 +121,12 @@ export default function Carousel({
|
|
|
121
121
|
// スクロール可能な場合にボタンを表示する
|
|
122
122
|
// scrollLeftが変化したときに処理する (アニメーション開始時 & 手動スクロール時)
|
|
123
123
|
useEffect(() => {
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
setLeftShow(
|
|
128
|
-
setRightShow(
|
|
129
|
-
onScrollStateChange?.(
|
|
124
|
+
const newLeftShow = scrollLeft > 0
|
|
125
|
+
const newRightShow = scrollLeft < maxScrollLeft && maxScrollLeft > 0
|
|
126
|
+
if (newLeftShow !== leftShow || newRightShow !== rightShow) {
|
|
127
|
+
setLeftShow(newLeftShow)
|
|
128
|
+
setRightShow(newRightShow)
|
|
129
|
+
onScrollStateChange?.(newLeftShow || newRightShow)
|
|
130
130
|
}
|
|
131
131
|
}, [leftShow, maxScrollLeft, onScrollStateChange, rightShow, scrollLeft])
|
|
132
132
|
|
|
@@ -141,7 +141,7 @@ export default function Carousel({
|
|
|
141
141
|
}
|
|
142
142
|
// スクロール位置を保存 (アニメーションの基準になる)
|
|
143
143
|
const manualScrollLeft = ref.current.scrollLeft
|
|
144
|
-
// 過剰にsetStateが走らないように
|
|
144
|
+
// 過剰にsetStateが走らないようにdebounceする
|
|
145
145
|
setScrollLeft(manualScrollLeft)
|
|
146
146
|
}, [animation, setScrollLeft, styles])
|
|
147
147
|
|
|
@@ -21,7 +21,7 @@ const makeUrl = (page: number) => `/${page}`
|
|
|
21
21
|
export function Default() {
|
|
22
22
|
return (
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
-
// @ts-expect-error
|
|
24
|
+
// @ts-expect-error TODO: adapt to react-router@6 (props should be covariant not bivariant)
|
|
25
25
|
<ComponentAbstraction components={{ Link: RouterLink }}>
|
|
26
26
|
<Router
|
|
27
27
|
initialEntries={Array.from({ length: 5 }).map((_, i) => makeUrl(i + 1))}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
MAIN_COLUMN_HORIZONTAL_MIN_MARGIN,
|
|
6
6
|
RESPONSIVE_LEFT_WIDTH,
|
|
7
7
|
RESPONSIVE_MAIN_MAX_WIDTH,
|
|
8
|
-
} from '../../foundation/
|
|
8
|
+
} from '../../foundation/constants'
|
|
9
9
|
import { useMediaScreen1 } from '../../foundation/hooks'
|
|
10
10
|
import { columnSystem, COLUMN_UNIT, GUTTER_UNIT } from '@charcoal-ui/foundation'
|
|
11
11
|
import { maxWidth } from '@charcoal-ui/utils'
|
|
@@ -19,7 +19,7 @@ export default {
|
|
|
19
19
|
export const Default = () => {
|
|
20
20
|
const primary = text('primary', 'Knob to change')
|
|
21
21
|
const secondary = text('secondary', '')
|
|
22
|
-
const disabled = boolean('
|
|
22
|
+
const disabled = boolean('disabled', false)
|
|
23
23
|
const padding = select('padding', { '16': 16, '24': 24 }, 24)
|
|
24
24
|
const noHover = boolean('noHover', false)
|
|
25
25
|
return (
|
|
@@ -26,28 +26,51 @@ export default {
|
|
|
26
26
|
min: 1,
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
|
+
pageRangeDisplayed: {
|
|
30
|
+
control: {
|
|
31
|
+
type: 'number',
|
|
32
|
+
min: 3,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
29
35
|
},
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
interface Props {
|
|
33
39
|
page: number
|
|
34
40
|
pageCount: number
|
|
41
|
+
pageRangeDisplayed?: number
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
const DefaultStory: Story<Props> = ({
|
|
44
|
+
const DefaultStory: Story<Props> = ({
|
|
45
|
+
page: defaultPage,
|
|
46
|
+
pageCount,
|
|
47
|
+
pageRangeDisplayed,
|
|
48
|
+
}) => {
|
|
38
49
|
const [page, setPage] = useState(defaultPage)
|
|
39
|
-
return
|
|
50
|
+
return (
|
|
51
|
+
<Pager
|
|
52
|
+
page={page}
|
|
53
|
+
onChange={setPage}
|
|
54
|
+
pageCount={pageCount}
|
|
55
|
+
pageRangeDisplayed={pageRangeDisplayed}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
40
58
|
}
|
|
41
59
|
|
|
42
60
|
export const Default = DefaultStory.bind({})
|
|
43
61
|
Default.args = {
|
|
44
62
|
page: 1,
|
|
45
63
|
pageCount: 10,
|
|
64
|
+
pageRangeDisplayed: undefined,
|
|
46
65
|
}
|
|
47
66
|
|
|
48
67
|
const makeUrl = (page: number) => `/${page}`
|
|
49
68
|
|
|
50
|
-
const LinkStory: Story<Props> = ({
|
|
69
|
+
const LinkStory: Story<Props> = ({
|
|
70
|
+
page: defaultPage,
|
|
71
|
+
pageCount,
|
|
72
|
+
pageRangeDisplayed,
|
|
73
|
+
}) => (
|
|
51
74
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
52
75
|
// @ts-ignore
|
|
53
76
|
<ComponentAbstraction components={{ Link: RouterLink }}>
|
|
@@ -60,18 +83,36 @@ const LinkStory: Story<Props> = ({ page: defaultPage, pageCount }) => (
|
|
|
60
83
|
<Routes>
|
|
61
84
|
<Route
|
|
62
85
|
path="/:page"
|
|
63
|
-
element={
|
|
86
|
+
element={
|
|
87
|
+
<CurrentPager
|
|
88
|
+
pageCount={pageCount}
|
|
89
|
+
pageRangeDisplayed={pageRangeDisplayed}
|
|
90
|
+
></CurrentPager>
|
|
91
|
+
}
|
|
64
92
|
/>
|
|
65
93
|
</Routes>
|
|
66
94
|
</Router>
|
|
67
95
|
</ComponentAbstraction>
|
|
68
96
|
)
|
|
69
97
|
|
|
70
|
-
function CurrentPager({
|
|
98
|
+
function CurrentPager({
|
|
99
|
+
pageCount,
|
|
100
|
+
pageRangeDisplayed,
|
|
101
|
+
}: {
|
|
102
|
+
pageCount: number
|
|
103
|
+
pageRangeDisplayed?: number
|
|
104
|
+
}) {
|
|
71
105
|
const params = useParams()
|
|
72
106
|
const page = params.page !== undefined ? parseInt(params.page, 10) : 1
|
|
73
107
|
|
|
74
|
-
return
|
|
108
|
+
return (
|
|
109
|
+
<LinkPager
|
|
110
|
+
makeUrl={makeUrl}
|
|
111
|
+
page={page}
|
|
112
|
+
pageCount={pageCount}
|
|
113
|
+
pageRangeDisplayed={pageRangeDisplayed}
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
75
116
|
}
|
|
76
117
|
|
|
77
118
|
export const Link = LinkStory.bind({})
|
|
@@ -103,3 +144,10 @@ One.args = {
|
|
|
103
144
|
page: 1,
|
|
104
145
|
pageCount: 1,
|
|
105
146
|
}
|
|
147
|
+
|
|
148
|
+
export const LittlePageRangeDisplayed = LinkStory.bind({})
|
|
149
|
+
LittlePageRangeDisplayed.args = {
|
|
150
|
+
page: 1,
|
|
151
|
+
pageCount: 10,
|
|
152
|
+
pageRangeDisplayed: 4,
|
|
153
|
+
}
|
|
@@ -6,7 +6,11 @@ import DotsIcon from '../icons/DotsIcon'
|
|
|
6
6
|
import WedgeIcon, { WedgeDirection } from '../icons/WedgeIcon'
|
|
7
7
|
import { useComponentAbstraction } from '@charcoal-ui/react'
|
|
8
8
|
|
|
9
|
-
function usePagerWindow(
|
|
9
|
+
function usePagerWindow(
|
|
10
|
+
page: number,
|
|
11
|
+
pageCount: number,
|
|
12
|
+
pageRangeDisplayed = 7
|
|
13
|
+
) {
|
|
10
14
|
// ページャーのリンク生成例:
|
|
11
15
|
//
|
|
12
16
|
// < [ 1 ] [*2*] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] >
|
|
@@ -24,28 +28,33 @@ function usePagerWindow(page: number, pageCount: number, windowSize = 7) {
|
|
|
24
28
|
// デザインの意図: 前後移動時のカーソル移動を最小限にする。
|
|
25
29
|
|
|
26
30
|
if (process.env.NODE_ENV !== 'production') {
|
|
27
|
-
warning((page | 0) === page, `\`page\` must be
|
|
31
|
+
warning((page | 0) === page, `\`page\` must be integer (${page})`)
|
|
28
32
|
warning(
|
|
29
33
|
(pageCount | 0) === pageCount,
|
|
30
|
-
`\`pageCount\` must be
|
|
34
|
+
`\`pageCount\` must be integer (${pageCount})`
|
|
31
35
|
)
|
|
36
|
+
warning(
|
|
37
|
+
(pageRangeDisplayed | 0) === pageRangeDisplayed,
|
|
38
|
+
`\`pageRangeDisplayed\` must be integer (${pageRangeDisplayed})`
|
|
39
|
+
)
|
|
40
|
+
warning(pageRangeDisplayed > 2, `\`windowSize\` must be greater than 2`)
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
const window = useMemo(() => {
|
|
35
44
|
const visibleFirstPage = 1
|
|
36
45
|
const visibleLastPage = Math.min(
|
|
37
46
|
pageCount,
|
|
38
|
-
Math.max(page + Math.floor(
|
|
47
|
+
Math.max(page + Math.floor(pageRangeDisplayed / 2), pageRangeDisplayed)
|
|
39
48
|
)
|
|
40
49
|
|
|
41
|
-
if (visibleLastPage <=
|
|
50
|
+
if (visibleLastPage <= pageRangeDisplayed) {
|
|
42
51
|
// 表示範囲が1-7ページなら省略は無い。
|
|
43
52
|
return Array.from(
|
|
44
53
|
{ length: 1 + visibleLastPage - visibleFirstPage },
|
|
45
54
|
(_, i) => visibleFirstPage + i
|
|
46
55
|
)
|
|
47
56
|
} else {
|
|
48
|
-
const start = visibleLastPage - (
|
|
57
|
+
const start = visibleLastPage - (pageRangeDisplayed - 1) + 2
|
|
49
58
|
return [
|
|
50
59
|
// 表示範囲が1-7ページを超えるなら、
|
|
51
60
|
// - 1ページ目は固定で表示する
|
|
@@ -58,7 +67,7 @@ function usePagerWindow(page: number, pageCount: number, windowSize = 7) {
|
|
|
58
67
|
),
|
|
59
68
|
]
|
|
60
69
|
}
|
|
61
|
-
}, [page, pageCount,
|
|
70
|
+
}, [page, pageCount, pageRangeDisplayed])
|
|
62
71
|
|
|
63
72
|
useDebugValue(window)
|
|
64
73
|
|
|
@@ -68,6 +77,7 @@ function usePagerWindow(page: number, pageCount: number, windowSize = 7) {
|
|
|
68
77
|
interface CommonProps {
|
|
69
78
|
page: number
|
|
70
79
|
pageCount: number
|
|
80
|
+
pageRangeDisplayed?: number
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
export interface PagerProps extends CommonProps {
|
|
@@ -75,9 +85,14 @@ export interface PagerProps extends CommonProps {
|
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
// this pager is just regular buttons; for links use LinkPager
|
|
78
|
-
export default memo(function Pager({
|
|
88
|
+
export default memo(function Pager({
|
|
89
|
+
page,
|
|
90
|
+
pageCount,
|
|
91
|
+
pageRangeDisplayed,
|
|
92
|
+
onChange,
|
|
93
|
+
}: PagerProps) {
|
|
79
94
|
// TODO: refactor Pager and LinkPager to use a common parent component
|
|
80
|
-
const window = usePagerWindow(page, pageCount)
|
|
95
|
+
const window = usePagerWindow(page, pageCount, pageRangeDisplayed)
|
|
81
96
|
const makeClickHandler = useCallback(
|
|
82
97
|
(value: number) => () => {
|
|
83
98
|
onChange(value)
|
|
@@ -132,9 +147,14 @@ export interface LinkPagerProps extends CommonProps {
|
|
|
132
147
|
makeUrl(page: number): string
|
|
133
148
|
}
|
|
134
149
|
|
|
135
|
-
export function LinkPager({
|
|
150
|
+
export function LinkPager({
|
|
151
|
+
page,
|
|
152
|
+
pageCount,
|
|
153
|
+
pageRangeDisplayed,
|
|
154
|
+
makeUrl,
|
|
155
|
+
}: LinkPagerProps) {
|
|
136
156
|
const { Link } = useComponentAbstraction()
|
|
137
|
-
const window = usePagerWindow(page, pageCount)
|
|
157
|
+
const window = usePagerWindow(page, pageCount, pageRangeDisplayed)
|
|
138
158
|
|
|
139
159
|
const hasNext = page < pageCount
|
|
140
160
|
const hasPrev = page > 1
|
package/src/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ export {
|
|
|
38
38
|
MAIN_COLUMN_HORIZONTAL_MIN_MARGIN,
|
|
39
39
|
RESPONSIVE_LEFT_WIDTH,
|
|
40
40
|
RESPONSIVE_MAIN_MAX_WIDTH,
|
|
41
|
-
} from './foundation/
|
|
41
|
+
} from './foundation/constants'
|
|
42
42
|
export { default as Carousel } from './components/Carousel'
|
|
43
43
|
export { useElementSize, useMedia, useMediaScreen1 } from './foundation/hooks'
|
|
44
44
|
export { default as Pager, LinkPager } from './components/Pager'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contants.d.ts","sourceRoot":"","sources":["../../src/foundation/contants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iCAAiC,KAAK,CAAA;AAEnD,eAAO,MAAM,qBAAqB,QACuB,CAAA;AACzD,eAAO,MAAM,yBAAyB,QAIrC,CAAA"}
|
|
File without changes
|