@instructure/ui-pagination 11.6.0 → 11.6.1-snapshot-129
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/CHANGELOG.md +42 -296
- package/es/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.js +2 -2
- package/es/Pagination/{PaginationButton → v1/PaginationButton}/index.js +1 -1
- package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.js +1 -1
- package/es/Pagination/{index.js → v1/index.js} +1 -1
- package/es/Pagination/v2/PaginationArrowButton/index.js +109 -0
- package/es/Pagination/v2/PaginationArrowButton/props.js +30 -0
- package/es/Pagination/v2/PaginationButton/index.js +77 -0
- package/es/Pagination/v2/PaginationButton/props.js +29 -0
- package/es/Pagination/v2/PaginationPageInput/index.js +189 -0
- package/es/Pagination/v2/PaginationPageInput/props.js +26 -0
- package/es/Pagination/v2/PaginationPageInput/styles.js +56 -0
- package/es/Pagination/v2/index.js +481 -0
- package/es/Pagination/v2/props.js +26 -0
- package/es/Pagination/v2/styles.js +58 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/es/exports/b.js +24 -0
- package/lib/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.js +8 -8
- package/lib/Pagination/{PaginationButton → v1/PaginationButton}/index.js +2 -2
- package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.js +2 -2
- package/lib/Pagination/{index.js → v1/index.js} +6 -6
- package/lib/Pagination/v2/PaginationArrowButton/index.js +115 -0
- package/lib/Pagination/v2/PaginationArrowButton/props.js +35 -0
- package/lib/Pagination/v2/PaginationButton/index.js +83 -0
- package/lib/Pagination/v2/PaginationButton/props.js +34 -0
- package/lib/Pagination/v2/PaginationPageInput/index.js +194 -0
- package/lib/Pagination/v2/PaginationPageInput/props.js +31 -0
- package/lib/Pagination/v2/PaginationPageInput/styles.js +62 -0
- package/lib/Pagination/v2/index.js +496 -0
- package/lib/Pagination/v2/props.js +31 -0
- package/lib/Pagination/v2/styles.js +64 -0
- package/lib/{index.js → exports/a.js} +3 -3
- package/lib/exports/b.js +18 -0
- package/package.json +48 -25
- package/src/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.tsx +2 -2
- package/src/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.ts +1 -1
- package/src/Pagination/{PaginationButton → v1/PaginationButton}/index.tsx +1 -1
- package/src/Pagination/{PaginationButton → v1/PaginationButton}/props.ts +1 -1
- package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.tsx +1 -1
- package/src/Pagination/{index.tsx → v1/index.tsx} +1 -1
- package/src/Pagination/v2/PaginationArrowButton/index.tsx +120 -0
- package/src/Pagination/v2/PaginationArrowButton/props.ts +74 -0
- package/src/Pagination/v2/PaginationButton/index.tsx +82 -0
- package/src/Pagination/v2/PaginationButton/props.ts +77 -0
- package/src/Pagination/v2/PaginationPageInput/index.tsx +242 -0
- package/src/Pagination/v2/PaginationPageInput/props.ts +95 -0
- package/src/Pagination/v2/PaginationPageInput/styles.ts +62 -0
- package/src/Pagination/v2/README.md +417 -0
- package/src/Pagination/v2/index.tsx +665 -0
- package/src/Pagination/v2/props.ts +245 -0
- package/src/Pagination/v2/styles.ts +64 -0
- package/src/exports/a.ts +29 -0
- package/src/exports/b.ts +29 -0
- package/tsconfig.build.json +1 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Pagination/v1/PaginationArrowButton/index.d.ts.map +1 -0
- package/types/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.d.ts +1 -1
- package/types/Pagination/v1/PaginationArrowButton/props.d.ts.map +1 -0
- package/types/Pagination/v1/PaginationButton/index.d.ts.map +1 -0
- package/types/Pagination/{PaginationButton → v1/PaginationButton}/props.d.ts +1 -1
- package/types/Pagination/v1/PaginationButton/props.d.ts.map +1 -0
- package/types/Pagination/v1/PaginationPageInput/index.d.ts.map +1 -0
- package/types/Pagination/v1/PaginationPageInput/props.d.ts.map +1 -0
- package/types/Pagination/v1/PaginationPageInput/styles.d.ts.map +1 -0
- package/types/Pagination/v1/PaginationPageInput/theme.d.ts.map +1 -0
- package/types/Pagination/v1/index.d.ts.map +1 -0
- package/types/Pagination/v1/props.d.ts.map +1 -0
- package/types/Pagination/v1/styles.d.ts.map +1 -0
- package/types/Pagination/v1/theme.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationArrowButton/index.d.ts +27 -0
- package/types/Pagination/v2/PaginationArrowButton/index.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationArrowButton/props.d.ts +17 -0
- package/types/Pagination/v2/PaginationArrowButton/props.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationButton/index.d.ts +26 -0
- package/types/Pagination/v2/PaginationButton/index.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationButton/props.d.ts +30 -0
- package/types/Pagination/v2/PaginationButton/props.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationPageInput/index.d.ts +50 -0
- package/types/Pagination/v2/PaginationPageInput/index.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationPageInput/props.d.ts +45 -0
- package/types/Pagination/v2/PaginationPageInput/props.d.ts.map +1 -0
- package/types/Pagination/v2/PaginationPageInput/styles.d.ts +16 -0
- package/types/Pagination/v2/PaginationPageInput/styles.d.ts.map +1 -0
- package/types/Pagination/v2/index.d.ts +106 -0
- package/types/Pagination/v2/index.d.ts.map +1 -0
- package/types/Pagination/v2/props.d.ts +138 -0
- package/types/Pagination/v2/props.d.ts.map +1 -0
- package/types/Pagination/v2/styles.d.ts +16 -0
- package/types/Pagination/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +5 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +5 -0
- package/types/exports/b.d.ts.map +1 -0
- package/src/index.ts +0 -29
- package/types/Pagination/PaginationArrowButton/index.d.ts.map +0 -1
- package/types/Pagination/PaginationArrowButton/props.d.ts.map +0 -1
- package/types/Pagination/PaginationButton/index.d.ts.map +0 -1
- package/types/Pagination/PaginationButton/props.d.ts.map +0 -1
- package/types/Pagination/PaginationPageInput/index.d.ts.map +0 -1
- package/types/Pagination/PaginationPageInput/props.d.ts.map +0 -1
- package/types/Pagination/PaginationPageInput/styles.d.ts.map +0 -1
- package/types/Pagination/PaginationPageInput/theme.d.ts.map +0 -1
- package/types/Pagination/index.d.ts.map +0 -1
- package/types/Pagination/props.d.ts.map +0 -1
- package/types/Pagination/styles.d.ts.map +0 -1
- package/types/Pagination/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.js +0 -0
- /package/es/Pagination/{PaginationButton → v1/PaginationButton}/props.js +0 -0
- /package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.js +0 -0
- /package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.js +0 -0
- /package/es/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.js +0 -0
- /package/es/Pagination/{props.js → v1/props.js} +0 -0
- /package/es/Pagination/{styles.js → v1/styles.js} +0 -0
- /package/es/Pagination/{theme.js → v1/theme.js} +0 -0
- /package/lib/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/props.js +0 -0
- /package/lib/Pagination/{PaginationButton → v1/PaginationButton}/props.js +0 -0
- /package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.js +0 -0
- /package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.js +0 -0
- /package/lib/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.js +0 -0
- /package/lib/Pagination/{props.js → v1/props.js} +0 -0
- /package/lib/Pagination/{styles.js → v1/styles.js} +0 -0
- /package/lib/Pagination/{theme.js → v1/theme.js} +0 -0
- /package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.ts +0 -0
- /package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.ts +0 -0
- /package/src/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.ts +0 -0
- /package/src/Pagination/{README.md → v1/README.md} +0 -0
- /package/src/Pagination/{props.ts → v1/props.ts} +0 -0
- /package/src/Pagination/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Pagination/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Pagination/{PaginationArrowButton → v1/PaginationArrowButton}/index.d.ts +0 -0
- /package/types/Pagination/{PaginationButton → v1/PaginationButton}/index.d.ts +0 -0
- /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/index.d.ts +0 -0
- /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/props.d.ts +0 -0
- /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/styles.d.ts +0 -0
- /package/types/Pagination/{PaginationPageInput → v1/PaginationPageInput}/theme.d.ts +0 -0
- /package/types/Pagination/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/Pagination/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Pagination/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Pagination/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { withStyle } from '@instructure/emotion'
|
|
28
|
+
import { Text } from '@instructure/ui-text/latest'
|
|
29
|
+
import { NumberInput } from '@instructure/ui-number-input/latest'
|
|
30
|
+
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
31
|
+
|
|
32
|
+
import generateStyle from './styles'
|
|
33
|
+
|
|
34
|
+
import { allowedProps } from './props'
|
|
35
|
+
import type {
|
|
36
|
+
PaginationPageInputProps,
|
|
37
|
+
PaginationPageInputState
|
|
38
|
+
} from './props'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
---
|
|
42
|
+
parent: Pagination
|
|
43
|
+
id: Pagination.PageInput
|
|
44
|
+
---
|
|
45
|
+
**/
|
|
46
|
+
@withStyle(generateStyle, 'PaginationPageInput')
|
|
47
|
+
class PaginationPageInput extends Component<
|
|
48
|
+
PaginationPageInputProps,
|
|
49
|
+
PaginationPageInputState
|
|
50
|
+
> {
|
|
51
|
+
static readonly componentId = 'Pagination.PageInput'
|
|
52
|
+
|
|
53
|
+
static allowedProps = allowedProps
|
|
54
|
+
static defaultProps = {
|
|
55
|
+
disabled: false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ref: HTMLSpanElement | null = null
|
|
59
|
+
|
|
60
|
+
constructor(props: PaginationPageInputProps) {
|
|
61
|
+
super(props)
|
|
62
|
+
|
|
63
|
+
this.state = this.initialState
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get currentPage() {
|
|
67
|
+
return this.props.currentPageIndex + 1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get initialState() {
|
|
71
|
+
return {
|
|
72
|
+
number: this.currentPage,
|
|
73
|
+
value: `${this.currentPage}`
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get MIN() {
|
|
78
|
+
return 1
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get MAX() {
|
|
82
|
+
return this.props.numberOfPages
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
componentDidMount() {
|
|
86
|
+
this.props.makeStyles?.()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
componentDidUpdate(prevProps: PaginationPageInputProps) {
|
|
90
|
+
this.props.makeStyles?.()
|
|
91
|
+
|
|
92
|
+
// when the current page changes from outside (e.g.: from arrow buttons),
|
|
93
|
+
// we update the initial state
|
|
94
|
+
if (this.props.currentPageIndex !== prevProps.currentPageIndex) {
|
|
95
|
+
this.resetInitialState()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
resetInitialState() {
|
|
100
|
+
this.setState(this.initialState)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
handleRef = (el: HTMLSpanElement | null) => {
|
|
104
|
+
this.ref = el
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
handleInputRef = (el: HTMLInputElement | null) => {
|
|
108
|
+
if (typeof this.props.inputRef === 'function') {
|
|
109
|
+
this.props.inputRef(el)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
handleChange = (
|
|
114
|
+
_event: React.ChangeEvent<HTMLInputElement>,
|
|
115
|
+
value: string
|
|
116
|
+
) => {
|
|
117
|
+
let newValue = value
|
|
118
|
+
|
|
119
|
+
// if the last character was not a number, don't accept it
|
|
120
|
+
if (value.length > 0 && isNaN(value.slice(-1) as any)) {
|
|
121
|
+
newValue = value.slice(0, -1)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.setState({
|
|
125
|
+
number: newValue ? Number(newValue) : this.MIN,
|
|
126
|
+
value: newValue
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
|
|
131
|
+
const { key } = event
|
|
132
|
+
|
|
133
|
+
if (key.toLowerCase() === 'enter') {
|
|
134
|
+
const { value, number } = this.state
|
|
135
|
+
|
|
136
|
+
// If it is invalid, we reset the input to the current page
|
|
137
|
+
if (value === '' || isNaN(value as any)) {
|
|
138
|
+
this.resetInitialState()
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this.setNewPage(event, number)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
handleDecrement = (
|
|
147
|
+
event:
|
|
148
|
+
| React.KeyboardEvent<HTMLInputElement>
|
|
149
|
+
| React.MouseEvent<HTMLButtonElement>
|
|
150
|
+
) => {
|
|
151
|
+
this.setNewPage(event, Math.floor(this.currentPage - 1))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
handleIncrement = (
|
|
155
|
+
event:
|
|
156
|
+
| React.KeyboardEvent<HTMLInputElement>
|
|
157
|
+
| React.MouseEvent<HTMLButtonElement>
|
|
158
|
+
) => {
|
|
159
|
+
this.setNewPage(event, Math.floor(this.currentPage + 1))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
|
|
163
|
+
if (Math.round(this.state.number) !== this.currentPage) {
|
|
164
|
+
this.setNewPage(event, Math.round(this.state.number))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
getNumberWithinRange(n: number) {
|
|
169
|
+
if (n < this.MIN) return this.MIN
|
|
170
|
+
if (n > this.MAX) return this.MAX
|
|
171
|
+
return n
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
setNewPage(
|
|
175
|
+
event:
|
|
176
|
+
| React.KeyboardEvent<HTMLInputElement>
|
|
177
|
+
| React.MouseEvent<HTMLButtonElement>
|
|
178
|
+
| React.FocusEvent<HTMLInputElement>,
|
|
179
|
+
n: number
|
|
180
|
+
) {
|
|
181
|
+
const number = this.getNumberWithinRange(n)
|
|
182
|
+
|
|
183
|
+
this.setState({
|
|
184
|
+
number,
|
|
185
|
+
value: `${number}`
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
this.props.onChange(event, number - 1)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
renderLabel() {
|
|
192
|
+
const { label, numberOfPages, styles } = this.props
|
|
193
|
+
|
|
194
|
+
return typeof label === 'function' && label(numberOfPages) ? (
|
|
195
|
+
<Text variant="content">
|
|
196
|
+
<span css={styles?.inputLabel}>{label(numberOfPages)}</span>
|
|
197
|
+
</Text>
|
|
198
|
+
) : null
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
renderScreenReaderLabel() {
|
|
202
|
+
const { screenReaderLabel, numberOfPages } = this.props
|
|
203
|
+
return (
|
|
204
|
+
<ScreenReaderContent>
|
|
205
|
+
{screenReaderLabel(this.currentPage, numberOfPages)}
|
|
206
|
+
</ScreenReaderContent>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
render() {
|
|
211
|
+
const { styles, disabled } = this.props
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<span
|
|
215
|
+
css={styles?.paginationPageInput}
|
|
216
|
+
ref={this.handleRef}
|
|
217
|
+
data-cid="PaginationPageInput"
|
|
218
|
+
>
|
|
219
|
+
<span css={styles?.numberInput}>
|
|
220
|
+
<NumberInput
|
|
221
|
+
renderLabel={this.renderScreenReaderLabel()}
|
|
222
|
+
onBlur={this.handleBlur}
|
|
223
|
+
onChange={this.handleChange}
|
|
224
|
+
onDecrement={this.handleDecrement}
|
|
225
|
+
onIncrement={this.handleIncrement}
|
|
226
|
+
onKeyDown={this.handleKeyDown.bind(this)}
|
|
227
|
+
interaction={disabled ? 'disabled' : 'enabled'}
|
|
228
|
+
showArrows={false}
|
|
229
|
+
value={this.state.value}
|
|
230
|
+
width="100%"
|
|
231
|
+
textAlign="center"
|
|
232
|
+
inputRef={this.handleInputRef}
|
|
233
|
+
/>
|
|
234
|
+
</span>
|
|
235
|
+
{this.renderLabel()}
|
|
236
|
+
</span>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export default PaginationPageInput
|
|
242
|
+
export { PaginationPageInput }
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
26
|
+
import type { PaginationPageInputTheme } from '@instructure/shared-types'
|
|
27
|
+
import React from 'react'
|
|
28
|
+
type PaginationPageInputOwnProps = {
|
|
29
|
+
/**
|
|
30
|
+
* The number of pages in total
|
|
31
|
+
*/
|
|
32
|
+
numberOfPages: number
|
|
33
|
+
/**
|
|
34
|
+
* The index of the current page
|
|
35
|
+
*/
|
|
36
|
+
currentPageIndex: number
|
|
37
|
+
/**
|
|
38
|
+
* Fires when a new page index is selected
|
|
39
|
+
*/
|
|
40
|
+
onChange: (
|
|
41
|
+
event:
|
|
42
|
+
| React.KeyboardEvent<HTMLInputElement>
|
|
43
|
+
| React.MouseEvent<HTMLButtonElement>
|
|
44
|
+
| React.FocusEvent<HTMLInputElement>,
|
|
45
|
+
pageIndex: number
|
|
46
|
+
) => void
|
|
47
|
+
/**
|
|
48
|
+
* ScreenReaderLabel for number input
|
|
49
|
+
*/
|
|
50
|
+
screenReaderLabel: (currentPage: number, numberOfPages: number) => string
|
|
51
|
+
/**
|
|
52
|
+
* Label for number input
|
|
53
|
+
*/
|
|
54
|
+
label?: (numberOfPages: number) => React.ReactNode
|
|
55
|
+
/**
|
|
56
|
+
* Disables interaction with the input
|
|
57
|
+
*/
|
|
58
|
+
disabled?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* provides a reference to the underlying html root element
|
|
61
|
+
*/
|
|
62
|
+
inputRef?: (element: HTMLInputElement | null) => void
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type PropKeys = keyof PaginationPageInputOwnProps
|
|
66
|
+
|
|
67
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
68
|
+
|
|
69
|
+
type PaginationPageInputProps = PaginationPageInputOwnProps &
|
|
70
|
+
WithStyleProps<PaginationPageInputTheme, PaginationPageInputStyle>
|
|
71
|
+
|
|
72
|
+
type PaginationPageInputStyle = ComponentStyle<
|
|
73
|
+
'paginationPageInput' | 'numberInput' | 'inputLabel'
|
|
74
|
+
>
|
|
75
|
+
|
|
76
|
+
type PaginationPageInputState = {
|
|
77
|
+
number: number
|
|
78
|
+
value: string
|
|
79
|
+
}
|
|
80
|
+
const allowedProps: AllowedPropKeys = [
|
|
81
|
+
'numberOfPages',
|
|
82
|
+
'currentPageIndex',
|
|
83
|
+
'onChange',
|
|
84
|
+
'screenReaderLabel',
|
|
85
|
+
'label',
|
|
86
|
+
'disabled',
|
|
87
|
+
'inputRef'
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
export type {
|
|
91
|
+
PaginationPageInputProps,
|
|
92
|
+
PaginationPageInputStyle,
|
|
93
|
+
PaginationPageInputState
|
|
94
|
+
}
|
|
95
|
+
export { allowedProps }
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { NewComponentTypes } from '@instructure/ui-themes'
|
|
26
|
+
import type { PaginationPageInputStyle } from './props'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ---
|
|
30
|
+
* private: true
|
|
31
|
+
* ---
|
|
32
|
+
* Generates the style object from the theme and provided additional information
|
|
33
|
+
* @param {Object} componentTheme The theme variable object.
|
|
34
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
35
|
+
* @param {Object} sharedTokens Shared token object that stores common values for the theme.
|
|
36
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
37
|
+
* @return {Object} The final style object, which will be used in the component
|
|
38
|
+
*/
|
|
39
|
+
const generateStyle = (
|
|
40
|
+
componentTheme: NewComponentTypes['PaginationPageInput']
|
|
41
|
+
): PaginationPageInputStyle => {
|
|
42
|
+
return {
|
|
43
|
+
paginationPageInput: {
|
|
44
|
+
label: 'paginationPageInput',
|
|
45
|
+
display: 'inline-flex',
|
|
46
|
+
alignItems: 'center',
|
|
47
|
+
margin: `0 ${componentTheme.inputSpacing}`
|
|
48
|
+
},
|
|
49
|
+
numberInput: {
|
|
50
|
+
label: 'paginationPageInput__input',
|
|
51
|
+
width: componentTheme.inputWidth
|
|
52
|
+
},
|
|
53
|
+
inputLabel: {
|
|
54
|
+
label: 'paginationPageInput__inputLabel',
|
|
55
|
+
marginInlineStart: componentTheme.inputSpacing,
|
|
56
|
+
whiteSpace: 'nowrap',
|
|
57
|
+
color: componentTheme.labelColor
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default generateStyle
|