idea-react 3.0.0-rc.0 → 3.0.0-rc.1

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.
@@ -64,42 +64,52 @@ export const Row = polymorphic<RowProps>(
64
64
  Row.displayName = 'Row';
65
65
 
66
66
  export interface ColProps extends ComponentPropsWithRef<'div'> {
67
- xs?: BreakpointColSize;
68
- sm?: BreakpointColSize;
69
- md?: BreakpointColSize;
70
- lg?: BreakpointColSize;
71
- xl?: BreakpointColSize;
72
- '2xl'?: BreakpointColSize;
67
+ xs?: ColBreakpoint;
68
+ sm?: ColBreakpoint;
69
+ md?: ColBreakpoint;
70
+ lg?: ColBreakpoint;
71
+ xl?: ColBreakpoint;
72
+ '2xl'?: ColBreakpoint;
73
73
  }
74
74
 
75
+ export type ColOrder = number | 'first' | 'last';
76
+
77
+ export interface ColBreakpointOptions {
78
+ span?: BreakpointColSize;
79
+ offset?: number;
80
+ order?: ColOrder;
81
+ }
82
+
83
+ export type ColBreakpoint = BreakpointColSize | ColBreakpointOptions;
84
+
75
85
  export const Col = polymorphic<ColProps>(
76
86
  ({ as: Root = 'div', xs, sm, md, lg, xl, '2xl': xxl, className, ...props }) => {
77
- const sizes: [Breakpoint, BreakpointColSize | undefined][] = [
87
+ const sizes: [Breakpoint | undefined, ColBreakpoint | undefined][] = [
88
+ [undefined, xs],
78
89
  ['sm', sm],
79
90
  ['md', md],
80
91
  ['lg', lg],
81
92
  ['xl', xl],
82
93
  ['2xl', xxl]
83
94
  ];
84
- const sized = sizes.some(([, size]) => size !== undefined);
85
-
86
- return (
87
- <Root
88
- {...props}
89
- className={classNames(
90
- {
91
- col: (xs === undefined && !sized) || xs === true,
92
- [`col-${xs}`]: xs !== undefined && xs !== true
93
- },
94
- sizes.map(
95
- ([breakpoint, size]) =>
96
- size !== undefined &&
97
- (size === true ? `${breakpoint}:col` : `${breakpoint}:col-${size}`)
98
- ),
99
- className
100
- )}
101
- />
95
+ const hasSpan = sizes.some(([, options]) =>
96
+ typeof options === 'object' ? options.span !== undefined : options !== undefined
102
97
  );
98
+ const classes = sizes.map(([breakpoint, options]) => {
99
+ if (options === undefined) return [];
100
+
101
+ const prefix = breakpoint ? `${breakpoint}:` : '';
102
+ const { span, offset, order } =
103
+ typeof options === 'object' ? options : { span: options };
104
+
105
+ return [
106
+ span !== undefined && `${prefix}col${span === true ? '' : `-${span}`}`,
107
+ offset !== undefined && `${prefix}offset-${offset}`,
108
+ order !== undefined && `${prefix}order-${order}`
109
+ ];
110
+ });
111
+
112
+ return <Root {...props} className={classNames(!hasSpan && 'col', classes, className)} />;
103
113
  }
104
114
  );
105
115
  Col.displayName = 'Col';
@@ -0,0 +1,29 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, CSSProperties } from 'react';
3
+
4
+ import { polymorphic } from '../Helper/Polymorphic';
5
+
6
+ export type AspectRatio = 'auto' | '1x1' | '4x3' | '16x9' | '21x9';
7
+ export type CustomAspectRatio = `${number} / ${number}`;
8
+
9
+ export type RatioProps = ComponentPropsWithRef<'div'> & {
10
+ aspectRatio?: AspectRatio | CustomAspectRatio;
11
+ };
12
+
13
+ export const Ratio = polymorphic<RatioProps>(
14
+ ({ as: Root = 'div', aspectRatio = '1x1', className, style, ...props }) => {
15
+ const preset = /^(auto|1x1|4x3|16x9|21x9)$/.test(aspectRatio);
16
+ const ratioStyle: CSSProperties & { '--bs-ratio'?: string } = preset
17
+ ? (style ?? {})
18
+ : { ...style, '--bs-ratio': aspectRatio };
19
+
20
+ return (
21
+ <Root
22
+ {...props}
23
+ className={classNames(`ratio-${preset ? aspectRatio : 'auto'}`, className)}
24
+ style={ratioStyle}
25
+ />
26
+ );
27
+ }
28
+ );
29
+ Ratio.displayName = 'Ratio';
@@ -1 +1,2 @@
1
1
  export * from './Grid';
2
+ export * from './Ratio';
package/source/types.d.ts CHANGED
@@ -10,3 +10,7 @@ declare module '*.module.css' {
10
10
  const classes: Readonly<Record<string, string>>;
11
11
  export default classes;
12
12
  }
13
+ declare module '*.module.less' {
14
+ const classes: Readonly<Record<string, string>>;
15
+ export default classes;
16
+ }