@momo-kits/foundation 0.169.7-beta.10 → 0.169.7-beta.11

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,13 +1,12 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { View, ViewProps } from 'react-native';
3
- import { GRID_GUTTER, GRID_MARGIN } from './constants';
4
- import { useGridSystem } from './useGridSystem';
3
+ import { useGridSystem, useScreenLayout } from './utils';
5
4
  import { GridContextProps } from './types';
6
5
  import { GridContext } from './index';
7
6
  import { Image } from '../Image';
8
7
  import { ApplicationContext } from '../Context';
9
8
  import styles from './styles';
10
- import { Radius, Shadow } from '../Consts';
9
+ import { Radius, Shadow, Spacing } from '../Consts';
11
10
 
12
11
  export interface CardProps extends ViewProps {
13
12
  /**
@@ -29,11 +28,12 @@ const Card: React.FC<CardProps> = ({
29
28
  ...props
30
29
  }) => {
31
30
  const { theme } = useContext(ApplicationContext);
32
- const { numberOfColumns, gridWidth, gridOffset } = useGridSystem();
31
+ const { numberOfColumns } = useGridSystem();
32
+ const { contentWidth } = useScreenLayout();
33
33
 
34
- const gutterSize = GRID_GUTTER;
35
- const margin = GRID_MARGIN;
36
- const widthSection = gridWidth - margin * 2;
34
+ const gutterSize = 8;
35
+ const margin = 12;
36
+ const widthSection = contentWidth - margin * 2;
37
37
  let sizePerSpan =
38
38
  (widthSection - margin * 2 - gutterSize * (numberOfColumns - 1)) /
39
39
  numberOfColumns -
@@ -41,7 +41,7 @@ const Card: React.FC<CardProps> = ({
41
41
 
42
42
  const gridContext: GridContextProps = {
43
43
  numberOfColumns,
44
- gutterSize: GRID_GUTTER,
44
+ gutterSize: Spacing.S,
45
45
  sizePerSpan,
46
46
  getSizeSpan: span => {
47
47
  return sizePerSpan * span + gutterSize * (span - 1);
@@ -60,7 +60,7 @@ const Card: React.FC<CardProps> = ({
60
60
  styles.card,
61
61
  {
62
62
  width: widthSection,
63
- marginHorizontal: gridOffset + margin,
63
+ marginHorizontal: margin,
64
64
  gap: gutterSize,
65
65
  },
66
66
  !!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
- * Represents the width of the Card component in terms of span numbers (1-36, out of the grid's 12, 24 or 36 columns).
10
+ * Represents the width of the Card component in terms of span numbers (1-12).
11
11
  */
12
12
  widthSpan?: SpanNumber;
13
13
 
14
14
  /**
15
- * Optional. Represents the height of the Card component in terms of span numbers (1-36, out of the grid's 12, 24 or 36 columns).
15
+ * Optional. Represents the height of the Card component in terms of span numbers (1-12).
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 { GRID_GUTTER, GRID_MARGIN } from './constants';
4
- import { useGridSystem } from './useGridSystem';
3
+ import { useGridSystem, useScreenLayout } from './utils';
5
4
  import { GridContextProps } from './types';
6
5
  import { GridContext } from './index';
7
6
  import styles from './styles';
8
7
  import { Image } from '../Image';
8
+ import { Spacing } from '../Consts';
9
9
 
10
10
  export interface SectionProps extends ViewProps {
11
11
  /**
@@ -33,14 +33,15 @@ const Section: React.FC<SectionProps> = ({
33
33
  style,
34
34
  ...props
35
35
  }) => {
36
- const { numberOfColumns, gridWidth, gridOffset } = useGridSystem();
36
+ const { numberOfColumns } = useGridSystem();
37
+ const { contentWidth } = useScreenLayout();
37
38
 
38
- const gutterSize = GRID_GUTTER;
39
+ const gutterSize = 12;
39
40
  let margin = 0;
40
41
  if (useMargin) {
41
- margin = GRID_MARGIN;
42
+ margin = 12;
42
43
  }
43
- const widthSection = gridWidth - margin * 2;
44
+ const widthSection = contentWidth - margin * 2;
44
45
 
45
46
  const sizePerSpan =
46
47
  (widthSection - gutterSize * (numberOfColumns - 1)) / numberOfColumns -
@@ -48,7 +49,7 @@ const Section: React.FC<SectionProps> = ({
48
49
 
49
50
  const gridContext: GridContextProps = {
50
51
  numberOfColumns,
51
- gutterSize: GRID_GUTTER,
52
+ gutterSize: Spacing.M,
52
53
  sizePerSpan,
53
54
  getSizeSpan: span => {
54
55
  return span * sizePerSpan + gutterSize * (span - 1);
@@ -66,7 +67,7 @@ const Section: React.FC<SectionProps> = ({
66
67
  styles.rowWrap,
67
68
  {
68
69
  width: widthSection,
69
- marginHorizontal: gridOffset + margin,
70
+ marginHorizontal: margin,
70
71
  gap: gutterSize,
71
72
  },
72
73
  ]}
package/Layout/types.ts CHANGED
@@ -15,43 +15,7 @@ export type ScreenRef = {
15
15
  */
16
16
  setSearchHeader: (params: SearchHeaderProps) => void;
17
17
  };
18
- export type SpanNumber =
19
- | 1
20
- | 2
21
- | 3
22
- | 4
23
- | 5
24
- | 6
25
- | 7
26
- | 8
27
- | 9
28
- | 10
29
- | 11
30
- | 12
31
- | 13
32
- | 14
33
- | 15
34
- | 16
35
- | 17
36
- | 18
37
- | 19
38
- | 20
39
- | 21
40
- | 22
41
- | 23
42
- | 24
43
- | 25
44
- | 26
45
- | 27
46
- | 28
47
- | 29
48
- | 30
49
- | 31
50
- | 32
51
- | 33
52
- | 34
53
- | 35
54
- | 36;
18
+ export type SpanNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
55
19
 
56
20
  export type GridContextProps = {
57
21
  /**
package/Layout/utils.ts CHANGED
@@ -364,6 +364,12 @@ const useSideBarItemStyle = (
364
364
  };
365
365
  };
366
366
 
367
+ const useGridSystem = () => {
368
+ const { contentWidth } = useScreenLayout();
369
+ const numberOfColumns = contentWidth > 600 ? 24 : 12;
370
+ return { numberOfColumns };
371
+ };
372
+
367
373
  export type { ScreenLayout, SideBarEdge, SideBarLayout, StatusBarClearance };
368
374
 
369
375
  export {
@@ -372,6 +378,7 @@ export {
372
378
  InnerEdgeStyles,
373
379
  getHeaderMargin,
374
380
  getHeaderRowOptions,
381
+ useGridSystem,
375
382
  useScreenLayout,
376
383
  useSideBarItemStyle,
377
384
  validateChildren,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.7-beta.10",
3
+ "version": "0.169.7-beta.11",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -1,19 +0,0 @@
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
- };
@@ -1,49 +0,0 @@
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 };