app-studio 0.1.21 → 0.1.23
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/app-studio.cjs.development.js +110 -92
- package/dist/app-studio.cjs.development.js.map +1 -1
- package/dist/app-studio.cjs.production.min.js +3 -3
- package/dist/app-studio.cjs.production.min.js.map +1 -1
- package/dist/app-studio.esm.js +111 -93
- package/dist/app-studio.esm.js.map +1 -1
- package/dist/components/Element.d.ts +2 -4
- package/dist/components/Image.d.ts +2 -2
- package/dist/components/Text.d.ts +2 -2
- package/package.json +1 -1
- package/dist/stories/Button.d.ts +0 -29
- package/dist/stories/Header.d.ts +0 -13
- package/dist/stories/Page.d.ts +0 -3
- package/dist/stories/Page.stories.d.ts +0 -13
|
@@ -569,6 +569,60 @@ const isStyleProp = property => {
|
|
|
569
569
|
return StyleProps[property] !== undefined;
|
|
570
570
|
};
|
|
571
571
|
|
|
572
|
+
const defaultBreakpointsConfig = {
|
|
573
|
+
xs: 0,
|
|
574
|
+
sm: 340,
|
|
575
|
+
md: 560,
|
|
576
|
+
lg: 1080,
|
|
577
|
+
xl: 1300
|
|
578
|
+
};
|
|
579
|
+
const defaultDeviceConfig = {
|
|
580
|
+
mobile: ['xs', 'sm'],
|
|
581
|
+
tablet: ['md', 'lg'],
|
|
582
|
+
desktop: ['lg', 'xl']
|
|
583
|
+
};
|
|
584
|
+
const getMediaQueries = b => {
|
|
585
|
+
const defaultKeys = Object.keys(b);
|
|
586
|
+
const breakpointValue = defaultKeys.map(breakpoint => {
|
|
587
|
+
const value = {
|
|
588
|
+
breakpoint: breakpoint,
|
|
589
|
+
min: b[breakpoint],
|
|
590
|
+
max: 0
|
|
591
|
+
};
|
|
592
|
+
return value;
|
|
593
|
+
}).sort((a, b) => a.min - b.min);
|
|
594
|
+
breakpointValue.reduce((a, b) => {
|
|
595
|
+
if (b) a.max = b.min;
|
|
596
|
+
return b;
|
|
597
|
+
});
|
|
598
|
+
const query = {};
|
|
599
|
+
breakpointValue.map(sizeScreen => {
|
|
600
|
+
query[sizeScreen.breakpoint] = `only screen ${sizeScreen.min && sizeScreen.min >= 0 ? 'and (min-width:' + sizeScreen.min + 'px)' : ''} ${sizeScreen.max && sizeScreen.max >= 0 ? 'and (max-width:' + sizeScreen.max + 'px)' : ''}`;
|
|
601
|
+
});
|
|
602
|
+
return query;
|
|
603
|
+
};
|
|
604
|
+
const defaultScreenConfig = {
|
|
605
|
+
breakpoints: defaultBreakpointsConfig,
|
|
606
|
+
devices: defaultDeviceConfig,
|
|
607
|
+
mediaQueries: /*#__PURE__*/getMediaQueries(defaultBreakpointsConfig)
|
|
608
|
+
};
|
|
609
|
+
const ResponsiveContext = /*#__PURE__*/React.createContext(defaultScreenConfig);
|
|
610
|
+
const useResponsiveContext = () => React.useContext(ResponsiveContext);
|
|
611
|
+
const ResponsiveProvider = _ref => {
|
|
612
|
+
let {
|
|
613
|
+
breakpoints = defaultBreakpointsConfig,
|
|
614
|
+
devices = defaultDeviceConfig,
|
|
615
|
+
children
|
|
616
|
+
} = _ref;
|
|
617
|
+
return /*#__PURE__*/React__default.createElement(ResponsiveContext.Provider, {
|
|
618
|
+
value: {
|
|
619
|
+
breakpoints,
|
|
620
|
+
devices,
|
|
621
|
+
mediaQueries: getMediaQueries(breakpoints)
|
|
622
|
+
}
|
|
623
|
+
}, children);
|
|
624
|
+
};
|
|
625
|
+
|
|
572
626
|
const NumberPropsStyle = {};
|
|
573
627
|
const NumberProps = ['numberOfLines', 'fontWeight', 'timeStamp', 'flex', 'flexGrow', 'flexShrink', 'order', 'zIndex', 'aspectRatio', 'shadowOpacity', 'shadowRadius', 'scale', 'opacity', 'min', 'max', 'now'];
|
|
574
628
|
NumberProps.map(property => {
|
|
@@ -577,8 +631,12 @@ NumberProps.map(property => {
|
|
|
577
631
|
const setSize = (newSize, styleProps) => {
|
|
578
632
|
styleProps.height = styleProps.width = newSize;
|
|
579
633
|
};
|
|
580
|
-
const applyStyle =
|
|
634
|
+
const applyStyle = oldProps => {
|
|
581
635
|
//console.log({ applyStyle: props });
|
|
636
|
+
// eslint-disable-next-line prefer-const
|
|
637
|
+
let {
|
|
638
|
+
...props
|
|
639
|
+
} = oldProps;
|
|
582
640
|
const {
|
|
583
641
|
getColor
|
|
584
642
|
} = useTheme();
|
|
@@ -586,7 +644,10 @@ const applyStyle = props => {
|
|
|
586
644
|
mediaQueries,
|
|
587
645
|
devices
|
|
588
646
|
} = useResponsiveContext();
|
|
589
|
-
|
|
647
|
+
// eslint-disable-next-line prefer-const
|
|
648
|
+
let styleProps = {
|
|
649
|
+
native: {}
|
|
650
|
+
};
|
|
590
651
|
//const otherProps: any = {};
|
|
591
652
|
if (props.onClick && styleProps.cursor == undefined) {
|
|
592
653
|
styleProps.cursor = 'pointer';
|
|
@@ -622,6 +683,7 @@ const applyStyle = props => {
|
|
|
622
683
|
const shadowColor = Color.hex.rgb(props.shadow.shadowColor).join(',');
|
|
623
684
|
styleProps['boxShadow'] = `${props.shadow.shadowOffset.height}px ${props.shadow.shadowOffset.width}px ${props.shadow.shadowRadius}px rgba(${shadowColor},${props.shadow.shadowOpacity})`;
|
|
624
685
|
}
|
|
686
|
+
delete props['shadow'];
|
|
625
687
|
}
|
|
626
688
|
if (props.only) {
|
|
627
689
|
const {
|
|
@@ -639,39 +701,43 @@ const applyStyle = props => {
|
|
|
639
701
|
});
|
|
640
702
|
}
|
|
641
703
|
Object.keys(props).map(property => {
|
|
642
|
-
if (
|
|
643
|
-
if (
|
|
644
|
-
if (property === '
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
704
|
+
if (property !== 'shadow' && property !== 'size') {
|
|
705
|
+
if (isStyleProp(property) || property == 'on' || property == 'media') {
|
|
706
|
+
if (typeof props[property] === 'object') {
|
|
707
|
+
if (property === 'on') {
|
|
708
|
+
for (const event in props[property]) {
|
|
709
|
+
styleProps['&:' + event] = applyStyle(props[property][event]);
|
|
710
|
+
}
|
|
711
|
+
} else if (property === 'media') {
|
|
712
|
+
for (const screenOrDevices in props[property]) {
|
|
713
|
+
// console.log(screenOrDevices, mediaQueries[screenOrDevices]);
|
|
714
|
+
if (mediaQueries[screenOrDevices] !== undefined && props[property][screenOrDevices] !== undefined) {
|
|
715
|
+
styleProps['@media ' + mediaQueries[screenOrDevices]] = applyStyle(props[property][screenOrDevices]);
|
|
716
|
+
} else if (devices[screenOrDevices] !== undefined) {
|
|
717
|
+
// console.log(screen, devices[screenOrDevices], 'screen');
|
|
718
|
+
for (const deviceScreen in devices[screenOrDevices]) {
|
|
719
|
+
if (mediaQueries[devices[screenOrDevices][deviceScreen]] !== undefined && props[property][screenOrDevices] !== undefined) {
|
|
720
|
+
// console.log(
|
|
721
|
+
// screenOrDevices,
|
|
722
|
+
// props[property][screenOrDevices]
|
|
723
|
+
// );
|
|
724
|
+
styleProps['@media ' + mediaQueries[devices[screenOrDevices][deviceScreen]]] = applyStyle(props[property][screenOrDevices]);
|
|
725
|
+
}
|
|
662
726
|
}
|
|
663
727
|
}
|
|
664
728
|
}
|
|
729
|
+
} else {
|
|
730
|
+
styleProps[property] = applyStyle(props[property]);
|
|
665
731
|
}
|
|
732
|
+
} else if (typeof props[property] === 'number' && NumberPropsStyle[property] === undefined) {
|
|
733
|
+
styleProps[property] = props[property] + 'px';
|
|
734
|
+
} else if (property.toLowerCase().indexOf('color') !== -1) {
|
|
735
|
+
styleProps[property] = getColor(props[property]);
|
|
666
736
|
} else {
|
|
667
|
-
styleProps[property] =
|
|
737
|
+
styleProps[property] = props[property];
|
|
668
738
|
}
|
|
669
|
-
} else if (typeof props[property] === 'number' && NumberPropsStyle[property] === undefined) {
|
|
670
|
-
styleProps[property] = props[property] + 'px';
|
|
671
|
-
} else if (property.toLowerCase().indexOf('color') !== -1) {
|
|
672
|
-
styleProps[property] = getColor(props[property]);
|
|
673
739
|
} else {
|
|
674
|
-
styleProps[property] = props[property];
|
|
740
|
+
styleProps['native'][property] = props[property];
|
|
675
741
|
}
|
|
676
742
|
}
|
|
677
743
|
});
|
|
@@ -720,17 +786,23 @@ const applyStyle = props => {
|
|
|
720
786
|
// .join('\n');
|
|
721
787
|
// return mediaQueries;
|
|
722
788
|
// };
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
${dynamicStyle};
|
|
789
|
+
const getElementComponent = cssData => styled.div`
|
|
790
|
+
${cssData}
|
|
726
791
|
`;
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
|
|
792
|
+
const Element = props => {
|
|
793
|
+
// Utilisez useMemo pour mémoriser le résultat de `applyStyle`
|
|
794
|
+
const {
|
|
795
|
+
native = {},
|
|
796
|
+
...cssData
|
|
797
|
+
} = React.useMemo(() => applyStyle(props), [props]);
|
|
798
|
+
// Mémoriser le composant stylisé pour éviter de le recréer inutilement
|
|
799
|
+
const ElementComponent = React.useMemo(() => getElementComponent(cssData), [cssData]);
|
|
800
|
+
// Gérer le clic en un seul endroit pour éviter la duplication et l'incohérence
|
|
801
|
+
const handleClick = props.onPress !== undefined ? props.onPress : props.onClick;
|
|
802
|
+
return /*#__PURE__*/React__default.createElement(ElementComponent, Object.assign({}, native, {
|
|
803
|
+
onClick: handleClick
|
|
804
|
+
}));
|
|
805
|
+
};
|
|
734
806
|
|
|
735
807
|
const View = props => /*#__PURE__*/React__default.createElement(Element, Object.assign({}, props));
|
|
736
808
|
const Div = View;
|
|
@@ -837,60 +909,6 @@ function isMobile() {
|
|
|
837
909
|
return navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i);
|
|
838
910
|
}
|
|
839
911
|
|
|
840
|
-
const defaultBreakpointsConfig = {
|
|
841
|
-
xs: 0,
|
|
842
|
-
sm: 340,
|
|
843
|
-
md: 560,
|
|
844
|
-
lg: 1080,
|
|
845
|
-
xl: 1300
|
|
846
|
-
};
|
|
847
|
-
const defaultDeviceConfig = {
|
|
848
|
-
mobile: ['xs', 'sm'],
|
|
849
|
-
tablet: ['md', 'lg'],
|
|
850
|
-
desktop: ['lg', 'xl']
|
|
851
|
-
};
|
|
852
|
-
const getMediaQueries = b => {
|
|
853
|
-
const defaultKeys = Object.keys(b);
|
|
854
|
-
const breakpointValue = defaultKeys.map(breakpoint => {
|
|
855
|
-
const value = {
|
|
856
|
-
breakpoint: breakpoint,
|
|
857
|
-
min: b[breakpoint],
|
|
858
|
-
max: 0
|
|
859
|
-
};
|
|
860
|
-
return value;
|
|
861
|
-
}).sort((a, b) => a.min - b.min);
|
|
862
|
-
breakpointValue.reduce((a, b) => {
|
|
863
|
-
if (b) a.max = b.min;
|
|
864
|
-
return b;
|
|
865
|
-
});
|
|
866
|
-
const query = {};
|
|
867
|
-
breakpointValue.map(sizeScreen => {
|
|
868
|
-
query[sizeScreen.breakpoint] = `only screen ${sizeScreen.min && sizeScreen.min >= 0 ? 'and (min-width:' + sizeScreen.min + 'px)' : ''} ${sizeScreen.max && sizeScreen.max >= 0 ? 'and (max-width:' + sizeScreen.max + 'px)' : ''}`;
|
|
869
|
-
});
|
|
870
|
-
return query;
|
|
871
|
-
};
|
|
872
|
-
const defaultScreenConfig = {
|
|
873
|
-
breakpoints: defaultBreakpointsConfig,
|
|
874
|
-
devices: defaultDeviceConfig,
|
|
875
|
-
mediaQueries: /*#__PURE__*/getMediaQueries(defaultBreakpointsConfig)
|
|
876
|
-
};
|
|
877
|
-
const ResponsiveContext = /*#__PURE__*/React.createContext(defaultScreenConfig);
|
|
878
|
-
const useResponsiveContext = () => React.useContext(ResponsiveContext);
|
|
879
|
-
const ResponsiveProvider = _ref => {
|
|
880
|
-
let {
|
|
881
|
-
breakpoints = defaultBreakpointsConfig,
|
|
882
|
-
devices = defaultDeviceConfig,
|
|
883
|
-
children
|
|
884
|
-
} = _ref;
|
|
885
|
-
return /*#__PURE__*/React__default.createElement(ResponsiveContext.Provider, {
|
|
886
|
-
value: {
|
|
887
|
-
breakpoints,
|
|
888
|
-
devices,
|
|
889
|
-
mediaQueries: getMediaQueries(breakpoints)
|
|
890
|
-
}
|
|
891
|
-
}, children);
|
|
892
|
-
};
|
|
893
|
-
|
|
894
912
|
const useMount = callback => {
|
|
895
913
|
React.useEffect(() => {
|
|
896
914
|
callback();
|