@momo-kits/foundation 0.169.15 → 0.169.16-beta.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.
package/Layout/Card.tsx CHANGED
@@ -1,12 +1,13 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { View, ViewProps } from 'react-native';
3
- import { useGridSystem, useScreenLayout } from './utils';
3
+ import { GRID_GUTTER, GRID_MARGIN } from './constants';
4
+ import { useGridSystem } from './useGridSystem';
4
5
  import { GridContextProps } from './types';
5
6
  import { GridContext } from './index';
6
7
  import { Image } from '../Image';
7
8
  import { ApplicationContext } from '../Context';
8
9
  import styles from './styles';
9
- import { Radius, Shadow, Spacing } from '../Consts';
10
+ import { Radius, Shadow } from '../Consts';
10
11
 
11
12
  export interface CardProps extends ViewProps {
12
13
  /**
@@ -21,7 +22,7 @@ export interface CardProps extends ViewProps {
21
22
  }
22
23
 
23
24
  /**
24
- * Surface card across the content width minus 12pt margins, with its own grid for child
25
+ * Surface card across the grid width minus 12pt margins, with its own grid for child
25
26
  * Items; optional background image and light shadow.
26
27
  */
27
28
  const Card: React.FC<CardProps> = ({
@@ -32,19 +33,18 @@ const Card: React.FC<CardProps> = ({
32
33
  ...props
33
34
  }) => {
34
35
  const { theme } = useContext(ApplicationContext);
35
- const { numberOfColumns } = useGridSystem();
36
- const { contentWidth } = useScreenLayout();
36
+ const { numberOfColumns, gridWidth, gridOffset } = useGridSystem();
37
37
 
38
- const gutterSize = 8;
39
- const margin = 12;
40
- const widthSection = contentWidth - margin * 2;
38
+ const gutterSize = GRID_GUTTER;
39
+ const margin = GRID_MARGIN;
40
+ const widthSection = gridWidth - margin * 2;
41
41
  const innerWidth = widthSection - margin * 2;
42
42
  const columnsWidth = innerWidth - gutterSize * (numberOfColumns - 1);
43
43
  const sizePerSpan = columnsWidth / numberOfColumns - 1 / numberOfColumns;
44
44
 
45
45
  const gridContext: GridContextProps = {
46
46
  numberOfColumns,
47
- gutterSize: Spacing.S,
47
+ gutterSize: GRID_GUTTER,
48
48
  sizePerSpan,
49
49
  getSizeSpan: span => {
50
50
  return sizePerSpan * span + gutterSize * (span - 1);
@@ -63,7 +63,7 @@ const Card: React.FC<CardProps> = ({
63
63
  styles.card,
64
64
  {
65
65
  width: widthSection,
66
- marginHorizontal: margin,
66
+ marginHorizontal: gridOffset + margin,
67
67
  gap: gutterSize,
68
68
  },
69
69
  !!backgroundImage && { backgroundColor: undefined },
package/Layout/Item.tsx CHANGED
@@ -7,12 +7,12 @@ import { SpanNumber } from './types';
7
7
 
8
8
  export interface ItemProps extends ViewProps {
9
9
  /**
10
- * Width in grid columns (1-12). Defaults to the full row.
10
+ * Width in grid columns (1-36, out of the grid's 12, 24 or 36). Defaults to the full row.
11
11
  */
12
12
  widthSpan?: SpanNumber;
13
13
 
14
14
  /**
15
- * Optional. Height in grid spans (1-12). Unset keeps the content height.
15
+ * Optional. Height in grid spans (1-36, out of the grid's 12, 24 or 36). Unset keeps the content height.
16
16
  */
17
17
  heightSpan?: SpanNumber;
18
18
  }
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { View, ViewProps } from 'react-native';
3
- import { useGridSystem, useScreenLayout } from './utils';
3
+ import { GRID_GUTTER, GRID_MARGIN } from './constants';
4
+ import { useGridSystem } from './useGridSystem';
4
5
  import { GridContextProps } from './types';
5
6
  import { GridContext } from './index';
6
7
  import styles from './styles';
7
8
  import { Image } from '../Image';
8
- import { Spacing } from '../Consts';
9
9
 
10
10
  export interface SectionProps extends ViewProps {
11
11
  /**
@@ -37,22 +37,21 @@ const Section: React.FC<SectionProps> = ({
37
37
  style,
38
38
  ...props
39
39
  }) => {
40
- const { numberOfColumns } = useGridSystem();
41
- const { contentWidth } = useScreenLayout();
40
+ const { numberOfColumns, gridWidth, gridOffset } = useGridSystem();
42
41
 
43
- const gutterSize = 12;
42
+ const gutterSize = GRID_GUTTER;
44
43
  let margin = 0;
45
44
  if (useMargin) {
46
- margin = 12;
45
+ margin = GRID_MARGIN;
47
46
  }
48
- const widthSection = contentWidth - margin * 2;
47
+ const widthSection = gridWidth - margin * 2;
49
48
 
50
49
  const columnsWidth = widthSection - gutterSize * (numberOfColumns - 1);
51
50
  const sizePerSpan = columnsWidth / numberOfColumns - 1 / numberOfColumns;
52
51
 
53
52
  const gridContext: GridContextProps = {
54
53
  numberOfColumns,
55
- gutterSize: Spacing.M,
54
+ gutterSize: GRID_GUTTER,
56
55
  sizePerSpan,
57
56
  getSizeSpan: span => {
58
57
  return span * sizePerSpan + gutterSize * (span - 1);
@@ -70,7 +69,7 @@ const Section: React.FC<SectionProps> = ({
70
69
  styles.rowWrap,
71
70
  {
72
71
  width: widthSection,
73
- marginHorizontal: margin,
72
+ marginHorizontal: gridOffset + margin,
74
73
  gap: gutterSize,
75
74
  },
76
75
  ]}
@@ -0,0 +1,19 @@
1
+ const GRID_MARGIN = 12;
2
+ const GRID_GUTTER = 12;
3
+ const GRID_PHONE_MAX_WIDTH = 600;
4
+ const GRID_TABLET_MIN_WIDTH = 800;
5
+ const GRID_DESKTOP_MIN_WIDTH = 1100;
6
+ const GRID_PHONE_COLUMNS = 12;
7
+ const GRID_TABLET_COLUMNS = 24;
8
+ const GRID_DESKTOP_COLUMNS = 36;
9
+
10
+ export {
11
+ GRID_DESKTOP_COLUMNS,
12
+ GRID_DESKTOP_MIN_WIDTH,
13
+ GRID_GUTTER,
14
+ GRID_MARGIN,
15
+ GRID_PHONE_COLUMNS,
16
+ GRID_PHONE_MAX_WIDTH,
17
+ GRID_TABLET_COLUMNS,
18
+ GRID_TABLET_MIN_WIDTH,
19
+ };
package/Layout/types.ts CHANGED
@@ -13,7 +13,43 @@ export type ScreenRef = {
13
13
  */
14
14
  setSearchHeader: (params: SearchHeaderProps) => void;
15
15
  };
16
- export type SpanNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
16
+ export type SpanNumber =
17
+ | 1
18
+ | 2
19
+ | 3
20
+ | 4
21
+ | 5
22
+ | 6
23
+ | 7
24
+ | 8
25
+ | 9
26
+ | 10
27
+ | 11
28
+ | 12
29
+ | 13
30
+ | 14
31
+ | 15
32
+ | 16
33
+ | 17
34
+ | 18
35
+ | 19
36
+ | 20
37
+ | 21
38
+ | 22
39
+ | 23
40
+ | 24
41
+ | 25
42
+ | 26
43
+ | 27
44
+ | 28
45
+ | 29
46
+ | 30
47
+ | 31
48
+ | 32
49
+ | 33
50
+ | 34
51
+ | 35
52
+ | 36;
17
53
 
18
54
  export type GridContextProps = {
19
55
  /**
@@ -0,0 +1,49 @@
1
+ import {
2
+ GRID_DESKTOP_COLUMNS,
3
+ GRID_DESKTOP_MIN_WIDTH,
4
+ GRID_PHONE_COLUMNS,
5
+ GRID_PHONE_MAX_WIDTH,
6
+ GRID_TABLET_COLUMNS,
7
+ GRID_TABLET_MIN_WIDTH,
8
+ } from './constants';
9
+ import { useScreenLayout } from './utils';
10
+
11
+ /**
12
+ * Column count for a content width: 12 below 800pt, 24 below 1100pt, 36 from there
13
+ */
14
+ const getGridColumns = (width: number) => {
15
+ if (width >= GRID_DESKTOP_MIN_WIDTH) {
16
+ return GRID_DESKTOP_COLUMNS;
17
+ }
18
+ if (width >= GRID_TABLET_MIN_WIDTH) {
19
+ return GRID_TABLET_COLUMNS;
20
+ }
21
+ return GRID_PHONE_COLUMNS;
22
+ };
23
+
24
+ /**
25
+ * Grid width for a content width: the 12-column grid stops at 600pt and is centered,
26
+ * the wider grids fill the content
27
+ */
28
+ const getGridWidth = (width: number) => {
29
+ if (width < GRID_TABLET_MIN_WIDTH) {
30
+ return Math.min(width, GRID_PHONE_MAX_WIDTH);
31
+ }
32
+ return width;
33
+ };
34
+
35
+ /**
36
+ * Grid for the current content width: column count, grid width and the horizontal
37
+ * offset that centers a grid narrower than the content
38
+ */
39
+ const useGridSystem = () => {
40
+ const { contentWidth } = useScreenLayout();
41
+ const gridWidth = getGridWidth(contentWidth);
42
+ return {
43
+ numberOfColumns: getGridColumns(contentWidth),
44
+ gridWidth,
45
+ gridOffset: (contentWidth - gridWidth) / 2,
46
+ };
47
+ };
48
+
49
+ export { useGridSystem };
package/Layout/utils.ts CHANGED
@@ -357,13 +357,6 @@ const useSideBarItemStyle = (
357
357
  };
358
358
  };
359
359
 
360
- /** Column count of the content grid: 24 on content wider than 600pt, otherwise 12. */
361
- const useGridSystem = () => {
362
- const { contentWidth } = useScreenLayout();
363
- const numberOfColumns = contentWidth > 600 ? 24 : 12;
364
- return { numberOfColumns };
365
- };
366
-
367
360
  export type { ScreenLayout, SideBarEdge, SideBarLayout, StatusBarClearance };
368
361
 
369
362
  export {
@@ -372,7 +365,6 @@ export {
372
365
  InnerEdgeStyles,
373
366
  getHeaderMargin,
374
367
  getHeaderRowOptions,
375
- useGridSystem,
376
368
  useScreenLayout,
377
369
  useSideBarItemStyle,
378
370
  validateChildren,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.15",
3
+ "version": "0.169.16-beta.1",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},