idea-react 3.0.0-beta.3 → 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/dist/style.css CHANGED
@@ -1,3 +1,6 @@
1
+ .SzYbbW_paused .carousel-indicators .active:after {
2
+ animation-play-state: paused;
3
+ }
1
4
  .Ocw1GG_hiddenBackdrop {
2
5
  --bs-dialog-backdrop-bg: transparent;
3
6
  --bs-dialog-backdrop-blur: 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-react",
3
- "version": "3.0.0-beta.3",
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",
package/source/Button.tsx CHANGED
@@ -42,6 +42,12 @@ export const Button = polymorphic<ButtonProps>(
42
42
  const link = isButtonLink(attributes);
43
43
  const Root = RootAs ?? (link ? 'a' : 'button');
44
44
  const nativeButton = Root === 'button';
45
+ const onClick =
46
+ !nativeButton && disabled
47
+ ? typeof Root === 'string'
48
+ ? undefined
49
+ : preventNavigation
50
+ : attributes.onClick;
45
51
  const classes = classNames(
46
52
  variant === false ? undefined : variant ? `btn-${variant}` : icon ? undefined : 'btn',
47
53
  theme && `theme-${theme}`,
@@ -64,7 +70,7 @@ export const Button = polymorphic<ButtonProps>(
64
70
  : attributes['aria-pressed']
65
71
  }
66
72
  tabIndex={!nativeButton && disabled ? -1 : attributes.tabIndex}
67
- onClick={!nativeButton && disabled ? preventNavigation : attributes.onClick}
73
+ onClick={onClick}
68
74
  />
69
75
  );
70
76
  }
@@ -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
- renderControls = () => {
256
+ renderControl = (direction: 'previous' | 'next') => {
238
257
  const { controls = true, ends = 'loop' } = this.props;
239
258
  if (!controls) return null;
240
259
 
241
- const atStart = this.store.activeIndex === 0;
242
- const atEnd = this.store.activeIndex === this.getSlides().length - 1;
243
- const buttonClass =
244
- this.props.controlsPlacement === 'overlay'
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
- <button
251
- type="button"
252
- className={buttonClass}
253
- data-carousel-action="previous"
254
- aria-label="Previous"
255
- disabled={ends === 'stop' && atStart}
256
- >
257
- <Icon name="chevron-left" aria-hidden="true" />
258
- <span className="visually-hidden">Previous</span>
259
- </button>
260
- <button
261
- type="button"
262
- className={
263
- this.props.controlsPlacement === 'overlay'
264
- ? 'carousel-control-next'
265
- : 'btn btn-subtle theme-secondary'
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
- <button
306
+ <Button
298
307
  type="button"
299
- className="btn-icon btn-sm carousel-control-play-pause"
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
- <Icon name={this.store.playing ? 'pause-fill' : 'play-fill'} aria-hidden="true" />
304
- </button>
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
- { 'carousel-fade': fade, 'carousel-dark': dark, 'carousel-center': center },
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' && outerControls}
439
+ {controlsPlacement === 'top' && this.renderControls()}
374
440
  <div
375
441
  ref={this.track}
376
- className="carousel-inner"
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
- {placement && this.renderControls()}
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
  }
@@ -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
- private visible = true;
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.playing || this.hovering || !this.visible || this.count < 2) return;
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
  };
@@ -0,0 +1,3 @@
1
+ .paused :global(.carousel-indicators .active)::after {
2
+ animation-play-state: paused;
3
+ }
@@ -73,7 +73,7 @@ export const UserRankView = polymorphic<UserRankViewProps>(
73
73
  return (
74
74
  <Container as={RootAs} className={className} {...props}>
75
75
  <Row className={style.rankBox}>
76
- <Col span={12} lg={7}>
76
+ <Col xs={12} lg={7}>
77
77
  <div className={`shadow rounded-3 ${style.title}`}>
78
78
  <div className={style.medal}>
79
79
  <i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
@@ -93,7 +93,7 @@ export const UserRankView = polymorphic<UserRankViewProps>(
93
93
  {rank.slice(0, 3).map(renderMedal)}
94
94
  </ul>
95
95
  </Col>
96
- <Col span={12} lg={5}>
96
+ <Col xs={12} lg={5}>
97
97
  <Table className={`my-3 pt-2 ${style.restUsers}`} responsive>
98
98
  <tbody>{rank.slice(3, 10).map(renderRow)}</tbody>
99
99
  </Table>
package/source/Grid.tsx CHANGED
@@ -8,16 +8,15 @@ export type ColSize = number | 'auto';
8
8
  export type BreakpointColSize = ColSize | true;
9
9
 
10
10
  export interface ContainerProps extends ComponentPropsWithRef<'div'> {
11
- fluid?: boolean;
12
- breakpoint?: Breakpoint;
11
+ fluid?: boolean | Breakpoint;
13
12
  }
14
13
 
15
14
  export const Container = polymorphic<ContainerProps>(
16
- ({ as: Root = 'div', fluid, breakpoint, className, ...props }) => (
15
+ ({ as: Root = 'div', fluid, className, ...props }) => (
17
16
  <Root
18
17
  {...props}
19
18
  className={classNames(
20
- breakpoint ? `${breakpoint}:container` : fluid ? 'container-fluid' : 'container',
19
+ fluid === true ? 'container-fluid' : fluid ? `${fluid}:container` : 'container',
21
20
  className
22
21
  )}
23
22
  />
@@ -28,7 +27,7 @@ Container.displayName = 'Container';
28
27
  export type RowCols = number | 'auto';
29
28
 
30
29
  export interface RowProps extends ComponentPropsWithRef<'div'> {
31
- cols?: RowCols;
30
+ xs?: RowCols;
32
31
  sm?: RowCols;
33
32
  md?: RowCols;
34
33
  lg?: RowCols;
@@ -37,7 +36,7 @@ export interface RowProps extends ComponentPropsWithRef<'div'> {
37
36
  }
38
37
 
39
38
  export const Row = polymorphic<RowProps>(
40
- ({ as: Root = 'div', cols, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
39
+ ({ as: Root = 'div', xs, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
41
40
  const sizes: [Breakpoint, RowCols | undefined][] = [
42
41
  ['sm', sm],
43
42
  ['md', md],
@@ -51,7 +50,7 @@ export const Row = polymorphic<RowProps>(
51
50
  {...props}
52
51
  className={classNames(
53
52
  'row',
54
- cols !== undefined && `row-cols-${cols}`,
53
+ xs !== undefined && `row-cols-${xs}`,
55
54
  sizes.map(
56
55
  ([breakpoint, size]) =>
57
56
  size !== undefined && `${breakpoint}:row-cols-${size}`
@@ -65,7 +64,7 @@ export const Row = polymorphic<RowProps>(
65
64
  Row.displayName = 'Row';
66
65
 
67
66
  export interface ColProps extends ComponentPropsWithRef<'div'> {
68
- span?: ColSize;
67
+ xs?: BreakpointColSize;
69
68
  sm?: BreakpointColSize;
70
69
  md?: BreakpointColSize;
71
70
  lg?: BreakpointColSize;
@@ -74,7 +73,7 @@ export interface ColProps extends ComponentPropsWithRef<'div'> {
74
73
  }
75
74
 
76
75
  export const Col = polymorphic<ColProps>(
77
- ({ as: Root = 'div', span, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
76
+ ({ as: Root = 'div', xs, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
78
77
  const sizes: [Breakpoint, BreakpointColSize | undefined][] = [
79
78
  ['sm', sm],
80
79
  ['md', md],
@@ -88,8 +87,10 @@ export const Col = polymorphic<ColProps>(
88
87
  <Root
89
88
  {...props}
90
89
  className={classNames(
91
- !span && !sized && 'col',
92
- span !== undefined && `col-${span}`,
90
+ {
91
+ col: (xs === undefined && !sized) || xs === true,
92
+ [`col-${xs}`]: xs !== undefined && xs !== true
93
+ },
93
94
  sizes.map(
94
95
  ([breakpoint, size]) =>
95
96
  size !== undefined &&
@@ -1,5 +1,3 @@
1
- import './style.module.css';
2
-
3
1
  import classNames from 'classnames';
4
2
  import { ComponentPropsWithRef, CSSProperties } from 'react';
5
3
 
@@ -36,7 +34,9 @@ export const Progress = polymorphic<ProgressProps>(
36
34
 
37
35
  const current = Math.min(max, Math.max(min, value));
38
36
  const width = `${((current - min) / (max - min)) * 100}%`;
37
+ // Stacks set the offset to zero and fill each segment's inner bar.
39
38
  const progressStyle: CSSProperties & { '--_progress-width': string } = {
39
+ width: 'min(100%, calc(var(--_progress-width) + var(--_progress-stack-offset, 100%)))',
40
40
  ...style,
41
41
  '--_progress-width': width
42
42
  };
@@ -63,7 +63,7 @@ export const Progress = polymorphic<ProgressProps>(
63
63
  },
64
64
  barClass
65
65
  )}
66
- style={barStyle}
66
+ style={{ width: `var(--_progress-bar-width, ${width})`, ...barStyle }}
67
67
  >
68
68
  {children}
69
69
  </div>
@@ -74,8 +74,18 @@ export const Progress = polymorphic<ProgressProps>(
74
74
  Progress.displayName = 'Progress';
75
75
 
76
76
  export const ProgressStack = polymorphic<ComponentPropsWithRef<'div'>>(
77
- ({ as: Root = 'div', className, ...props }) => (
78
- <Root {...props} className={classNames('progress-stacked', className)} />
77
+ ({ as: Root = 'div', className, style, ...props }) => (
78
+ <Root
79
+ {...props}
80
+ className={classNames('progress-stacked', className)}
81
+ style={
82
+ {
83
+ '--_progress-stack-offset': '0%',
84
+ '--_progress-bar-width': '100%',
85
+ ...style
86
+ } as CSSProperties
87
+ }
88
+ />
79
89
  )
80
90
  );
81
91
  ProgressStack.displayName = 'ProgressStack';
@@ -1,15 +0,0 @@
1
- :global(.progress) {
2
- width: 100%;
3
- }
4
-
5
- :global(.progress) > :global(.progress-bar) {
6
- width: var(--_progress-width);
7
- }
8
-
9
- :global(.progress-stacked) > :global(.progress) {
10
- width: var(--_progress-width);
11
- }
12
-
13
- :global(.progress-stacked) > :global(.progress) > :global(.progress-bar) {
14
- width: 100%;
15
- }