idea-react 3.0.0-beta.4 → 3.0.0-beta.5
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/AGENTS.md +1 -0
- package/dist/index.d.mts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +13 -13
- package/dist/index.mjs +12 -12
- package/dist/style.css +3 -0
- package/package.json +2 -2
- package/source/Carousel/index.tsx +118 -57
- package/source/Carousel/model.ts +12 -8
- package/source/Carousel/style.module.css +3 -0
package/dist/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idea-react",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.5",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
5
|
"author": "shiy2008@gmail.com",
|
|
6
6
|
"description": "A React advanced components library based on TypeScript & Bootstrap, built by idea2app remote developers team.",
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
},
|
|
133
133
|
"scripts": {
|
|
134
134
|
"prepare": "husky",
|
|
135
|
-
"test": "lint-staged && node --import ./test/setup.mts --test --test-timeout=10000 \"test/**/*.test.tsx\"",
|
|
135
|
+
"test": "lint-staged && tsc --noEmit -p test/tsconfig.json && node --import ./test/setup.mts --test --test-timeout=10000 \"test/**/*.test.tsx\"",
|
|
136
136
|
"pack-docs": "rimraf docs/ && typedoc source/",
|
|
137
137
|
"start": "npm run pack-docs && web-server docs/ -p 8080 -o",
|
|
138
138
|
"build": "npm run pack-docs && tsdown",
|
|
@@ -16,10 +16,12 @@ import {
|
|
|
16
16
|
ReactNode
|
|
17
17
|
} from 'react';
|
|
18
18
|
|
|
19
|
+
import { Button } from '../Button';
|
|
19
20
|
import { Icon } from '../Extension/Icon';
|
|
20
21
|
import { polymorphic, PolymorphicClassProps } from '../Polymorphic';
|
|
21
22
|
import { CarouselEnds, CarouselModel } from './model';
|
|
22
23
|
import { CarouselScroll } from './scroll';
|
|
24
|
+
import styles from './style.module.css';
|
|
23
25
|
|
|
24
26
|
export interface CarouselSlideProps extends ComponentPropsWithRef<'div'> {
|
|
25
27
|
interval?: number;
|
|
@@ -41,14 +43,19 @@ export const CarouselSlide = polymorphic<CarouselSlideProps>(
|
|
|
41
43
|
CarouselSlide.displayName = 'CarouselSlide';
|
|
42
44
|
|
|
43
45
|
export interface CarouselProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
|
|
46
|
+
auto?: boolean;
|
|
44
47
|
autoplay?: boolean;
|
|
45
48
|
center?: boolean;
|
|
46
49
|
controls?: boolean;
|
|
47
50
|
controlsPlacement?: 'overlay' | 'top' | 'bottom';
|
|
51
|
+
controlsClassName?: string;
|
|
52
|
+
controlsStart?: ReactNode;
|
|
48
53
|
dark?: boolean;
|
|
49
54
|
ends?: CarouselEnds;
|
|
50
55
|
fade?: boolean;
|
|
51
56
|
indicators?: boolean;
|
|
57
|
+
indicatorPlacement?: 'start' | 'end' | 'between';
|
|
58
|
+
innerClassName?: string;
|
|
52
59
|
interval?: number;
|
|
53
60
|
items?: number;
|
|
54
61
|
itemsGap?: string | number;
|
|
@@ -84,6 +91,18 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
84
91
|
|
|
85
92
|
componentDidUpdate() {
|
|
86
93
|
this.updateStore();
|
|
94
|
+
|
|
95
|
+
const focused = document.activeElement;
|
|
96
|
+
if (
|
|
97
|
+
focused instanceof HTMLButtonElement &&
|
|
98
|
+
focused.disabled &&
|
|
99
|
+
this.root.current?.contains(focused)
|
|
100
|
+
) {
|
|
101
|
+
const action = focused.dataset.carouselAction === 'next' ? 'previous' : 'next';
|
|
102
|
+
this.root.current
|
|
103
|
+
.querySelector<HTMLButtonElement>(`[data-carousel-action="${action}"]`)
|
|
104
|
+
?.focus();
|
|
105
|
+
}
|
|
87
106
|
}
|
|
88
107
|
|
|
89
108
|
componentWillUnmount() {
|
|
@@ -234,44 +253,33 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
234
253
|
);
|
|
235
254
|
};
|
|
236
255
|
|
|
237
|
-
|
|
256
|
+
renderControl = (direction: 'previous' | 'next') => {
|
|
238
257
|
const { controls = true, ends = 'loop' } = this.props;
|
|
239
258
|
if (!controls) return null;
|
|
240
259
|
|
|
241
|
-
const
|
|
242
|
-
const atEnd = this.store.activeIndex === this.getSlides().length - 1;
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
? 'carousel-control-prev'
|
|
246
|
-
: 'btn btn-subtle theme-secondary';
|
|
260
|
+
const previous = direction === 'previous';
|
|
261
|
+
const atEnd = this.store.activeIndex === (previous ? 0 : this.getSlides().length - 1);
|
|
262
|
+
const overlay = (this.props.controlsPlacement ?? 'overlay') === 'overlay';
|
|
263
|
+
const label = previous ? 'Previous' : 'Next';
|
|
247
264
|
|
|
248
265
|
return (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
data-carousel-action="next"
|
|
268
|
-
aria-label="Next"
|
|
269
|
-
disabled={ends === 'stop' && atEnd}
|
|
270
|
-
>
|
|
271
|
-
<Icon name="chevron-right" aria-hidden="true" />
|
|
272
|
-
<span className="visually-hidden">Next</span>
|
|
273
|
-
</button>
|
|
274
|
-
</>
|
|
266
|
+
<Button
|
|
267
|
+
type="button"
|
|
268
|
+
variant={overlay ? 'subtle' : undefined}
|
|
269
|
+
theme={overlay ? 'secondary' : undefined}
|
|
270
|
+
size="sm"
|
|
271
|
+
data-carousel-action={direction}
|
|
272
|
+
aria-label={label}
|
|
273
|
+
disabled={ends === 'stop' && atEnd}
|
|
274
|
+
icon
|
|
275
|
+
>
|
|
276
|
+
<Icon
|
|
277
|
+
name={previous ? 'chevron-left' : 'chevron-right'}
|
|
278
|
+
size={1}
|
|
279
|
+
aria-hidden="true"
|
|
280
|
+
/>
|
|
281
|
+
<span className="visually-hidden">{label}</span>
|
|
282
|
+
</Button>
|
|
275
283
|
);
|
|
276
284
|
};
|
|
277
285
|
|
|
@@ -282,6 +290,7 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
282
290
|
<button
|
|
283
291
|
key={index}
|
|
284
292
|
type="button"
|
|
293
|
+
data-bs-target={this.props.id ? `#${this.props.id}` : ''}
|
|
285
294
|
data-carousel-action="slide"
|
|
286
295
|
data-index={index}
|
|
287
296
|
aria-label={`Slide ${index + 1}`}
|
|
@@ -294,15 +303,65 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
294
303
|
|
|
295
304
|
renderPlayPause = () =>
|
|
296
305
|
(this.props.playPause || this.props.autoplay) && (
|
|
297
|
-
<
|
|
306
|
+
<Button
|
|
298
307
|
type="button"
|
|
299
|
-
className=
|
|
308
|
+
className={classNames('carousel-control-play-pause', {
|
|
309
|
+
paused: !this.store.playing
|
|
310
|
+
})}
|
|
311
|
+
size="sm"
|
|
300
312
|
data-carousel-action="toggle"
|
|
301
313
|
aria-label={this.store.playing ? 'Pause' : 'Play'}
|
|
314
|
+
icon
|
|
315
|
+
>
|
|
316
|
+
<Icon
|
|
317
|
+
name={this.store.playing ? 'pause-fill' : 'play-fill'}
|
|
318
|
+
size={1}
|
|
319
|
+
aria-hidden="true"
|
|
320
|
+
/>
|
|
321
|
+
</Button>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
renderControls = () => {
|
|
325
|
+
const {
|
|
326
|
+
controls = true,
|
|
327
|
+
controlsPlacement = 'overlay',
|
|
328
|
+
controlsClassName = 'd-flex justify-content-between align-items-center',
|
|
329
|
+
controlsStart,
|
|
330
|
+
indicators,
|
|
331
|
+
indicatorPlacement = 'start',
|
|
332
|
+
autoplay,
|
|
333
|
+
playPause
|
|
334
|
+
} = this.props;
|
|
335
|
+
if (!controls && !indicators && !autoplay && !playPause && !controlsStart) return null;
|
|
336
|
+
|
|
337
|
+
const split = indicatorPlacement === 'between';
|
|
338
|
+
const previous = this.renderControl('previous');
|
|
339
|
+
const next = this.renderControl('next');
|
|
340
|
+
const buttons = (
|
|
341
|
+
<>
|
|
342
|
+
{this.renderPlayPause()}
|
|
343
|
+
{previous}
|
|
344
|
+
{next}
|
|
345
|
+
</>
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
return (
|
|
349
|
+
<div
|
|
350
|
+
className={
|
|
351
|
+
controlsPlacement === 'overlay'
|
|
352
|
+
? 'carousel-overlay-controls'
|
|
353
|
+
: controlsClassName
|
|
354
|
+
}
|
|
302
355
|
>
|
|
303
|
-
|
|
304
|
-
|
|
356
|
+
{controlsStart}
|
|
357
|
+
{indicatorPlacement === 'start' && this.renderIndicators()}
|
|
358
|
+
{split ? previous : <div className="d-inline-flex gap-1">{buttons}</div>}
|
|
359
|
+
{indicatorPlacement !== 'start' && this.renderIndicators()}
|
|
360
|
+
{split && this.renderPlayPause()}
|
|
361
|
+
{split && next}
|
|
362
|
+
</div>
|
|
305
363
|
);
|
|
364
|
+
};
|
|
306
365
|
|
|
307
366
|
render() {
|
|
308
367
|
const Root: ElementType = this.props.as ?? 'div';
|
|
@@ -310,17 +369,21 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
310
369
|
const slides = this.getSlides();
|
|
311
370
|
const {
|
|
312
371
|
as: _as,
|
|
372
|
+
auto,
|
|
313
373
|
autoplay: _autoplay,
|
|
314
374
|
center,
|
|
315
375
|
children: _children,
|
|
316
376
|
className,
|
|
317
377
|
controls: _controls,
|
|
318
378
|
controlsPlacement = 'overlay',
|
|
379
|
+
controlsClassName: _controlsClassName,
|
|
380
|
+
controlsStart: _controlsStart,
|
|
319
381
|
dark,
|
|
320
382
|
ends: _ends,
|
|
321
|
-
fade: _fade,
|
|
322
383
|
fade,
|
|
323
384
|
indicators: _indicators,
|
|
385
|
+
indicatorPlacement: _indicatorPlacement,
|
|
386
|
+
innerClassName,
|
|
324
387
|
interval: _interval,
|
|
325
388
|
items,
|
|
326
389
|
itemsGap,
|
|
@@ -338,17 +401,11 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
338
401
|
...style,
|
|
339
402
|
...(items && { '--bs-carousel-items': items }),
|
|
340
403
|
...(itemsGap !== undefined && { '--bs-carousel-items-gap': itemsGap }),
|
|
341
|
-
...(itemsPeek !== undefined && { '--bs-carousel-items-peek': itemsPeek })
|
|
404
|
+
...(itemsPeek !== undefined && { '--bs-carousel-items-peek': itemsPeek }),
|
|
405
|
+
...(this.store.playing && {
|
|
406
|
+
'--bs-carousel-interval': `${this.getSlideInterval(this.store.activeIndex)}ms`
|
|
407
|
+
})
|
|
342
408
|
} as CSSProperties;
|
|
343
|
-
const outerControls = (
|
|
344
|
-
<div className="d-flex justify-content-between align-items-center gap-2">
|
|
345
|
-
{this.renderIndicators()}
|
|
346
|
-
<div className="d-flex align-items-center gap-2">
|
|
347
|
-
{this.renderPlayPause()}
|
|
348
|
-
{this.renderControls()}
|
|
349
|
-
</div>
|
|
350
|
-
</div>
|
|
351
|
-
);
|
|
352
409
|
|
|
353
410
|
return (
|
|
354
411
|
<Root
|
|
@@ -356,13 +413,22 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
356
413
|
ref={this.root}
|
|
357
414
|
className={classNames(
|
|
358
415
|
'carousel',
|
|
359
|
-
{
|
|
416
|
+
{
|
|
417
|
+
'carousel-overlay': placement,
|
|
418
|
+
'carousel-auto': auto,
|
|
419
|
+
'carousel-fade': fade,
|
|
420
|
+
'carousel-dark': dark,
|
|
421
|
+
'carousel-center': center,
|
|
422
|
+
'carousel-playing': this.store.playing,
|
|
423
|
+
[styles.paused]: this.store.playing && !this.store.cycling
|
|
424
|
+
},
|
|
360
425
|
className
|
|
361
426
|
)}
|
|
362
427
|
style={styleWithItems}
|
|
363
428
|
role="region"
|
|
364
429
|
aria-label={this.props['aria-label'] ?? 'Carousel'}
|
|
365
430
|
aria-roledescription="carousel"
|
|
431
|
+
{...(dark && { 'data-bs-theme': 'dark' })}
|
|
366
432
|
onClick={this.handleClick}
|
|
367
433
|
onKeyDown={this.handleKeyDown}
|
|
368
434
|
onMouseEnter={this.handleMouseEnter}
|
|
@@ -370,22 +436,17 @@ export class Carousel<T extends ElementType | undefined = 'div'> extends Compone
|
|
|
370
436
|
onFocusCapture={this.handleFocusCapture}
|
|
371
437
|
onBlurCapture={this.handleBlurCapture}
|
|
372
438
|
>
|
|
373
|
-
{controlsPlacement === 'top' &&
|
|
439
|
+
{controlsPlacement === 'top' && this.renderControls()}
|
|
374
440
|
<div
|
|
375
441
|
ref={this.track}
|
|
376
|
-
className=
|
|
442
|
+
className={classNames('carousel-inner', innerClassName)}
|
|
377
443
|
tabIndex={0}
|
|
378
444
|
aria-label={this.props['aria-label'] ?? 'Carousel slides'}
|
|
379
445
|
onScroll={this.handleScroll}
|
|
380
446
|
>
|
|
381
447
|
{slides.map(this.renderSlide)}
|
|
382
448
|
</div>
|
|
383
|
-
{
|
|
384
|
-
{controlsPlacement === 'bottom' && outerControls}
|
|
385
|
-
{placement &&
|
|
386
|
-
(this.props.playPause || this.props.autoplay) &&
|
|
387
|
-
this.renderPlayPause()}
|
|
388
|
-
{placement && this.renderIndicators()}
|
|
449
|
+
{controlsPlacement !== 'top' && this.renderControls()}
|
|
389
450
|
</Root>
|
|
390
451
|
);
|
|
391
452
|
}
|
package/source/Carousel/model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { action, observable } from 'mobx';
|
|
1
|
+
import { action, computed, observable } from 'mobx';
|
|
2
2
|
|
|
3
3
|
export type CarouselEnds = 'loop' | 'wrap' | 'stop';
|
|
4
4
|
|
|
@@ -9,9 +9,13 @@ export class CarouselModel {
|
|
|
9
9
|
|
|
10
10
|
private timer?: ReturnType<typeof setTimeout>;
|
|
11
11
|
|
|
12
|
-
private hovering = false;
|
|
12
|
+
@observable private accessor hovering = false;
|
|
13
|
+
@observable private accessor visible = true;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
@computed
|
|
16
|
+
get cycling() {
|
|
17
|
+
return this.playing && !this.hovering && this.visible;
|
|
18
|
+
}
|
|
15
19
|
|
|
16
20
|
onChange?: (index: number) => unknown;
|
|
17
21
|
|
|
@@ -78,15 +82,15 @@ export class CarouselModel {
|
|
|
78
82
|
@action
|
|
79
83
|
toggle = () => (this.playing ? this.pause() : this.play());
|
|
80
84
|
|
|
81
|
-
setHovering = (hovering: boolean) => {
|
|
85
|
+
setHovering = action((hovering: boolean) => {
|
|
82
86
|
this.hovering = hovering;
|
|
83
87
|
this.schedule();
|
|
84
|
-
};
|
|
88
|
+
});
|
|
85
89
|
|
|
86
|
-
setVisible = (visible: boolean) => {
|
|
90
|
+
setVisible = action((visible: boolean) => {
|
|
87
91
|
this.visible = visible;
|
|
88
92
|
this.schedule();
|
|
89
|
-
};
|
|
93
|
+
});
|
|
90
94
|
|
|
91
95
|
update = (count: number, ends: CarouselEnds, interval: (index: number) => number) => {
|
|
92
96
|
this.count = count;
|
|
@@ -101,7 +105,7 @@ export class CarouselModel {
|
|
|
101
105
|
|
|
102
106
|
private schedule = () => {
|
|
103
107
|
this.clearTimer();
|
|
104
|
-
if (!this.
|
|
108
|
+
if (!this.cycling || this.count < 2) return;
|
|
105
109
|
|
|
106
110
|
this.timer = setTimeout(this.next, Math.max(0, this.interval(this.activeIndex)));
|
|
107
111
|
};
|