@teamturing/react-kit 1.4.0 → 2.0.0

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.
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { LayoutProps } from 'styled-system';
3
+ import { SxProp } from '../../utils/styled-system';
4
+ type Props = {} & SxProp & LayoutProps;
5
+ declare const Image: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, Props>>;
6
+ export default Image;
7
+ export type { Props as ImageProps };
@@ -0,0 +1,6 @@
1
+ import { ISection } from '../types';
2
+ type Props = {
3
+ section: ISection;
4
+ };
5
+ declare const EnigmaUI: ({ section: { views, responsiveLayout } }: Props) => import("react/jsx-runtime").JSX.Element;
6
+ export default EnigmaUI;
@@ -0,0 +1,8 @@
1
+ import { SingleColumnLayout as SingleColumnLayoutType } from '../../types';
2
+ type Props = {
3
+ layout: SingleColumnLayoutType;
4
+ viewsObject: any;
5
+ viewComponentsObject: any;
6
+ };
7
+ declare const SingleColumnLayout: ({ layout, viewsObject, viewComponentsObject }: Props) => import("react/jsx-runtime").JSX.Element;
8
+ export default SingleColumnLayout;
@@ -0,0 +1 @@
1
+ export { default as SingleColumnLayout } from './SingleColumnLayout';
@@ -0,0 +1,6 @@
1
+ import { ImageView as ImageViewType } from '../../types';
2
+ type Props = {
3
+ view: ImageViewType;
4
+ };
5
+ declare const ImageView: ({ view: { ...props } }: Props) => import("react/jsx-runtime").JSX.Element;
6
+ export default ImageView;
@@ -0,0 +1,6 @@
1
+ import { TextView as TextViewType } from '../../types';
2
+ type Props = {
3
+ view: TextViewType;
4
+ };
5
+ declare const TextView: ({ view: { text, textProps } }: Props) => import("react/jsx-runtime").JSX.Element;
6
+ export default TextView;
@@ -0,0 +1,2 @@
1
+ export { default as ImageView } from './ImageView';
2
+ export { default as TextView } from './TextView';
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Default Types
3
+ */
4
+ type TextProps = any;
5
+ type SpaceProps = any;
6
+ /**
7
+ * View Related Model
8
+ */
9
+ export type TextView = {
10
+ text: string;
11
+ textProps?: TextProps;
12
+ };
13
+ export type ImageView = {
14
+ src: string;
15
+ alt: string;
16
+ width: number;
17
+ height: number;
18
+ };
19
+ export type View = TextView | ImageView;
20
+ export type ViewComponentType = 'TextView' | 'ImageView';
21
+ export interface IViewContainer {
22
+ id: string;
23
+ viewComponentType: ViewComponentType;
24
+ view: View;
25
+ }
26
+ /**
27
+ * Layout Related Model
28
+ */
29
+ export interface IViewContainerDetail {
30
+ viewContainerId: string;
31
+ spaceProps: SpaceProps;
32
+ }
33
+ export type SingleColumnLayout = {
34
+ main: IViewContainerDetail[];
35
+ };
36
+ export type Layout = SingleColumnLayout;
37
+ export type LayoutComponentType = 'SingleColumnLayout';
38
+ export interface ILayoutContainer {
39
+ layoutComponentType: LayoutComponentType;
40
+ layout: Layout;
41
+ }
42
+ export interface IResponsiveLayoutContainer {
43
+ mobile: ILayoutContainer;
44
+ tablet?: ILayoutContainer;
45
+ desktop?: ILayoutContainer;
46
+ }
47
+ /**
48
+ * Section Related Model
49
+ */
50
+ export interface ISection {
51
+ id: string;
52
+ views: IViewContainer[];
53
+ responsiveLayout: IResponsiveLayoutContainer;
54
+ }
55
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * core components
3
+ */
1
4
  export { default as Button } from './core/Button';
2
5
  export type { ButtonProps } from './core/Button';
3
6
  export { default as Chip } from './core/Chip';
@@ -10,6 +13,8 @@ export { default as IconButton } from './core/IconButton';
10
13
  export type { IconButtonProps } from './core/IconButton';
11
14
  export { default as IconToggleButton } from './core/IconToggleButton';
12
15
  export type { IconToggleButtonProps } from './core/IconToggleButton';
16
+ export { default as Image } from './core/Image';
17
+ export type { ImageProps } from './core/Image';
13
18
  export { default as ItemList } from './core/ItemList';
14
19
  export type { ItemListProps } from './core/ItemList';
15
20
  export { default as Space } from './core/Space';
@@ -26,6 +31,13 @@ export { default as View } from './core/View';
26
31
  export type { ViewProps } from './core/View';
27
32
  export { default as UnstyledButton } from './core/_UnstyledButton';
28
33
  export type { UnstyledButtonProps } from './core/_UnstyledButton';
34
+ /**
35
+ * enigma component
36
+ */
37
+ export { default as EnigmaUI } from './enigma/EnigmaUI';
38
+ /**
39
+ * hooks
40
+ */
29
41
  export { default as useDevice } from './hook/useDevice';
30
42
  export { default as useOutsideClick } from './hook/useOutsideClick';
31
43
  export { default as useProvidedOrCreatedRef } from './hook/useProvidedOrCreatedRef';
package/dist/index.js CHANGED
@@ -26,6 +26,15 @@ function _interopNamespace(e) {
26
26
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
27
  var styled__default = /*#__PURE__*/_interopDefault(styled);
28
28
 
29
+ const device = {
30
+ deviceDesktop: 1280,
31
+ deviceTablet: 900,
32
+ deviceMobile: 640
33
+ };
34
+
35
+ const baseBreakpoints = [device.deviceMobile, device.deviceTablet, device.deviceDesktop];
36
+ const breakpoints = baseBreakpoints.map(value => `${value + 1}px`);
37
+
29
38
  const gray = {
30
39
  gray50: '#F9FAFB',
31
40
  gray100: '#F3F4F6',
@@ -3849,6 +3858,11 @@ const BaseIconToggleButton = styled__default.default(UnstyledButton)(({
3849
3858
  }
3850
3859
  }), sx);
3851
3860
 
3861
+ const Image = styled__default.default.img`
3862
+ ${layout}
3863
+ ${sx}
3864
+ `;
3865
+
3852
3866
  const ItemList = ({
3853
3867
  items,
3854
3868
  renderItem,
@@ -3937,6 +3951,126 @@ const StyledIcon = ({
3937
3951
  children: /*#__PURE__*/jsxRuntimeExports.jsx(Icon, {})
3938
3952
  });
3939
3953
 
3954
+ const useMediaQuery = query => {
3955
+ const getMatches = query => {
3956
+ /**
3957
+ * SSR 문제를 방지하기 위해 있습니다.
3958
+ */
3959
+ if (typeof window !== 'undefined') {
3960
+ return window.matchMedia(query).matches;
3961
+ }
3962
+ return false;
3963
+ };
3964
+ const [matches, setMatches] = React.useState(getMatches(query));
3965
+ function handleChange() {
3966
+ setMatches(getMatches(query));
3967
+ }
3968
+ React.useEffect(() => {
3969
+ const matchMedia = window.matchMedia(query);
3970
+
3971
+ /**
3972
+ * 클라이언트에서 mediaQuery를 반영하기 위해 로드됩니다.
3973
+ */
3974
+ handleChange();
3975
+ if (matchMedia.addListener) {
3976
+ matchMedia.addListener(handleChange);
3977
+ } else {
3978
+ matchMedia.addEventListener('change', handleChange);
3979
+ }
3980
+ return () => {
3981
+ if (matchMedia.removeListener) {
3982
+ matchMedia.removeListener(handleChange);
3983
+ } else {
3984
+ matchMedia.removeEventListener('change', handleChange);
3985
+ }
3986
+ };
3987
+ }, [query]);
3988
+ return matches;
3989
+ };
3990
+
3991
+ const SingleColumnLayout = ({
3992
+ layout,
3993
+ viewsObject,
3994
+ viewComponentsObject
3995
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(ItemList, {
3996
+ items: layout.main,
3997
+ renderItem: ({
3998
+ viewContainerId
3999
+ }) => {
4000
+ const view = viewsObject[viewContainerId];
4001
+ const ViewComponent = viewComponentsObject[viewContainerId];
4002
+ return ViewComponent ? /*#__PURE__*/jsxRuntimeExports.jsx(ViewComponent, {
4003
+ view: view
4004
+ }) : null;
4005
+ },
4006
+ renderItemWrapper: (children, {
4007
+ viewContainerId,
4008
+ spaceProps
4009
+ }, i) => /*#__PURE__*/jsxRuntimeExports.jsx(Space, {
4010
+ ...spaceProps,
4011
+ children: children
4012
+ }, [viewContainerId, `${i}`].join('-'))
4013
+ });
4014
+
4015
+ const ImageView = ({
4016
+ view: {
4017
+ ...props
4018
+ }
4019
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(Image, {
4020
+ loading: 'lazy',
4021
+ ...props
4022
+ });
4023
+
4024
+ const TextView = ({
4025
+ view: {
4026
+ text,
4027
+ textProps
4028
+ }
4029
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
4030
+ ...textProps,
4031
+ children: text
4032
+ });
4033
+
4034
+ const EnigmaUI = ({
4035
+ section: {
4036
+ views,
4037
+ responsiveLayout
4038
+ }
4039
+ }) => {
4040
+ const isMatchDesktop = useMediaQuery(`screen and (min-width: ${breakpoints[1]})`);
4041
+ const isMatchTablet = useMediaQuery(`screen and (min-width: ${breakpoints[0]})`);
4042
+ const media = isMatchDesktop ? 'desktop' : !isMatchDesktop && isMatchTablet ? 'tablet' : 'mobile';
4043
+ const layoutContainer = responsiveLayout[media] || responsiveLayout['desktop'] || responsiveLayout['tablet'] || responsiveLayout['mobile'];
4044
+ const LayoutComponent = getLayoutComponent(layoutContainer);
4045
+ const layout = layoutContainer.layout;
4046
+ const viewsObject = Object.fromEntries(views.map(viewContainer => {
4047
+ return [viewContainer.id, viewContainer.view];
4048
+ }));
4049
+ const viewComponentsObject = Object.fromEntries(views.map(view => {
4050
+ return [view.id, getViewComponent(view)];
4051
+ }));
4052
+ return /*#__PURE__*/jsxRuntimeExports.jsx(LayoutComponent, {
4053
+ layout: layout,
4054
+ viewsObject: viewsObject,
4055
+ viewComponentsObject: viewComponentsObject
4056
+ });
4057
+ };
4058
+ const getLayoutComponent = layoutContainer => {
4059
+ const renderableLayoutComponent = {
4060
+ SingleColumnLayout: SingleColumnLayout
4061
+ };
4062
+ const LayoutComponent = renderableLayoutComponent[layoutContainer.layoutComponentType];
4063
+ return LayoutComponent;
4064
+ };
4065
+ const getViewComponent = viewContainer => {
4066
+ const renderableViewComponent = {
4067
+ TextView: TextView,
4068
+ ImageView: ImageView
4069
+ };
4070
+ const ViewComponent = renderableViewComponent[viewContainer.viewComponentType];
4071
+ return ViewComponent;
4072
+ };
4073
+
3940
4074
  /**
3941
4075
  * lodash (Custom Build) <https://lodash.com/>
3942
4076
  * Build: `lodash modularize exports="npm" -o ./`
@@ -4441,10 +4575,12 @@ const useToggleHandler = ({
4441
4575
 
4442
4576
  exports.Button = Button;
4443
4577
  exports.Chip = Chip;
4578
+ exports.EnigmaUI = EnigmaUI;
4444
4579
  exports.GradientText = GradientText;
4445
4580
  exports.Grid = index$1;
4446
4581
  exports.IconButton = IconButton;
4447
4582
  exports.IconToggleButton = IconToggleButton;
4583
+ exports.Image = Image;
4448
4584
  exports.ItemList = ItemList;
4449
4585
  exports.Space = Space;
4450
4586
  exports.Spinner = Spinner;
@@ -0,0 +1,11 @@
1
+ import styled from 'styled-components';
2
+ import '../../node_modules/styled-system/dist/index.esm.js';
3
+ import { sx } from '../../utils/styled-system/index.js';
4
+ import { layout } from '../../node_modules/@styled-system/layout/dist/index.esm.js';
5
+
6
+ const Image = styled.img`
7
+ ${layout}
8
+ ${sx}
9
+ `;
10
+
11
+ export { Image as default };
@@ -0,0 +1,48 @@
1
+ import breakpoints from '../../packages/token-studio/esm/token/breakpoints/index.js';
2
+ import useMediaQuery from '../../hook/useMediaQuery.js';
3
+ import SingleColumnLayout from '../Layout/SingleColumnLayout/index.js';
4
+ import ImageView from '../View/ImageView/index.js';
5
+ import TextView from '../View/TextView/index.js';
6
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
7
+
8
+ const EnigmaUI = ({
9
+ section: {
10
+ views,
11
+ responsiveLayout
12
+ }
13
+ }) => {
14
+ const isMatchDesktop = useMediaQuery(`screen and (min-width: ${breakpoints[1]})`);
15
+ const isMatchTablet = useMediaQuery(`screen and (min-width: ${breakpoints[0]})`);
16
+ const media = isMatchDesktop ? 'desktop' : !isMatchDesktop && isMatchTablet ? 'tablet' : 'mobile';
17
+ const layoutContainer = responsiveLayout[media] || responsiveLayout['desktop'] || responsiveLayout['tablet'] || responsiveLayout['mobile'];
18
+ const LayoutComponent = getLayoutComponent(layoutContainer);
19
+ const layout = layoutContainer.layout;
20
+ const viewsObject = Object.fromEntries(views.map(viewContainer => {
21
+ return [viewContainer.id, viewContainer.view];
22
+ }));
23
+ const viewComponentsObject = Object.fromEntries(views.map(view => {
24
+ return [view.id, getViewComponent(view)];
25
+ }));
26
+ return /*#__PURE__*/jsxRuntimeExports.jsx(LayoutComponent, {
27
+ layout: layout,
28
+ viewsObject: viewsObject,
29
+ viewComponentsObject: viewComponentsObject
30
+ });
31
+ };
32
+ const getLayoutComponent = layoutContainer => {
33
+ const renderableLayoutComponent = {
34
+ SingleColumnLayout: SingleColumnLayout
35
+ };
36
+ const LayoutComponent = renderableLayoutComponent[layoutContainer.layoutComponentType];
37
+ return LayoutComponent;
38
+ };
39
+ const getViewComponent = viewContainer => {
40
+ const renderableViewComponent = {
41
+ TextView: TextView,
42
+ ImageView: ImageView
43
+ };
44
+ const ViewComponent = renderableViewComponent[viewContainer.viewComponentType];
45
+ return ViewComponent;
46
+ };
47
+
48
+ export { EnigmaUI as default };
@@ -0,0 +1,29 @@
1
+ import ItemList from '../../../core/ItemList/index.js';
2
+ import Space from '../../../core/Space/index.js';
3
+ import { j as jsxRuntimeExports } from '../../../node_modules/react/jsx-runtime.js';
4
+
5
+ const SingleColumnLayout = ({
6
+ layout,
7
+ viewsObject,
8
+ viewComponentsObject
9
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(ItemList, {
10
+ items: layout.main,
11
+ renderItem: ({
12
+ viewContainerId
13
+ }) => {
14
+ const view = viewsObject[viewContainerId];
15
+ const ViewComponent = viewComponentsObject[viewContainerId];
16
+ return ViewComponent ? /*#__PURE__*/jsxRuntimeExports.jsx(ViewComponent, {
17
+ view: view
18
+ }) : null;
19
+ },
20
+ renderItemWrapper: (children, {
21
+ viewContainerId,
22
+ spaceProps
23
+ }, i) => /*#__PURE__*/jsxRuntimeExports.jsx(Space, {
24
+ ...spaceProps,
25
+ children: children
26
+ }, [viewContainerId, `${i}`].join('-'))
27
+ });
28
+
29
+ export { SingleColumnLayout as default };
@@ -0,0 +1,13 @@
1
+ import Image from '../../../core/Image/index.js';
2
+ import { j as jsxRuntimeExports } from '../../../node_modules/react/jsx-runtime.js';
3
+
4
+ const ImageView = ({
5
+ view: {
6
+ ...props
7
+ }
8
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(Image, {
9
+ loading: 'lazy',
10
+ ...props
11
+ });
12
+
13
+ export { ImageView as default };
@@ -0,0 +1,14 @@
1
+ import Text from '../../../core/Text/index.js';
2
+ import { j as jsxRuntimeExports } from '../../../node_modules/react/jsx-runtime.js';
3
+
4
+ const TextView = ({
5
+ view: {
6
+ text,
7
+ textProps
8
+ }
9
+ }) => /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
10
+ ...textProps,
11
+ children: text
12
+ });
13
+
14
+ export { TextView as default };
@@ -0,0 +1,40 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ const useMediaQuery = query => {
4
+ const getMatches = query => {
5
+ /**
6
+ * SSR 문제를 방지하기 위해 있습니다.
7
+ */
8
+ if (typeof window !== 'undefined') {
9
+ return window.matchMedia(query).matches;
10
+ }
11
+ return false;
12
+ };
13
+ const [matches, setMatches] = useState(getMatches(query));
14
+ function handleChange() {
15
+ setMatches(getMatches(query));
16
+ }
17
+ useEffect(() => {
18
+ const matchMedia = window.matchMedia(query);
19
+
20
+ /**
21
+ * 클라이언트에서 mediaQuery를 반영하기 위해 로드됩니다.
22
+ */
23
+ handleChange();
24
+ if (matchMedia.addListener) {
25
+ matchMedia.addListener(handleChange);
26
+ } else {
27
+ matchMedia.addEventListener('change', handleChange);
28
+ }
29
+ return () => {
30
+ if (matchMedia.removeListener) {
31
+ matchMedia.removeListener(handleChange);
32
+ } else {
33
+ matchMedia.removeEventListener('change', handleChange);
34
+ }
35
+ };
36
+ }, [query]);
37
+ return matches;
38
+ };
39
+
40
+ export { useMediaQuery as default };
package/esm/index.js CHANGED
@@ -4,6 +4,7 @@ export { default as GradientText } from './core/GradientText/index.js';
4
4
  export { default as Grid } from './core/Grid/index.js';
5
5
  export { default as IconButton } from './core/IconButton/index.js';
6
6
  export { default as IconToggleButton } from './core/IconToggleButton/index.js';
7
+ export { default as Image } from './core/Image/index.js';
7
8
  export { default as ItemList } from './core/ItemList/index.js';
8
9
  export { default as Space } from './core/Space/index.js';
9
10
  export { default as Spinner } from './core/Spinner/index.js';
@@ -12,6 +13,7 @@ export { default as StyledIcon } from './core/StyledIcon/index.js';
12
13
  export { default as Text } from './core/Text/index.js';
13
14
  export { default as View } from './core/View/index.js';
14
15
  export { default as UnstyledButton } from './core/_UnstyledButton.js';
16
+ export { default as EnigmaUI } from './enigma/EnigmaUI/index.js';
15
17
  export { default as useDevice } from './hook/useDevice.js';
16
18
  export { default as useOutsideClick } from './hook/useOutsideClick.js';
17
19
  export { default as useProvidedOrCreatedRef } from './hook/useProvidedOrCreatedRef.js';
@@ -0,0 +1,7 @@
1
+ const device = {
2
+ deviceDesktop: 1280,
3
+ deviceTablet: 900,
4
+ deviceMobile: 640
5
+ };
6
+
7
+ export { device as default };
@@ -0,0 +1,6 @@
1
+ import device from '../../foundation/breakpoint/device.js';
2
+
3
+ const baseBreakpoints = [device.deviceMobile, device.deviceTablet, device.deviceDesktop];
4
+ const breakpoints = baseBreakpoints.map(value => `${value + 1}px`);
5
+
6
+ export { baseBreakpoints, breakpoints as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -55,5 +55,5 @@
55
55
  "lodash.throttle": "^4.1.1",
56
56
  "styled-system": "^5.1.5"
57
57
  },
58
- "gitHead": "e302acb51e25f77d313c324dafbaaed9655abeae"
58
+ "gitHead": "6360f6a5b2308f6bda0bf7ea8c23a13ff3ad9050"
59
59
  }