@cleartrip/ct-design-safe-area-container 4.0.0-SNAPSHOT-test.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.
- package/README.md +73 -0
- package/dist/SafeAreaContainer.d.ts +5 -0
- package/dist/SafeAreaContainer.d.ts.map +1 -0
- package/dist/SafeAreaContainer.native.d.ts +5 -0
- package/dist/SafeAreaContainer.native.d.ts.map +1 -0
- package/dist/ct-design-safe-area-container.browser.cjs.js +2 -0
- package/dist/ct-design-safe-area-container.browser.cjs.js.map +1 -0
- package/dist/ct-design-safe-area-container.browser.esm.js +2 -0
- package/dist/ct-design-safe-area-container.browser.esm.js.map +1 -0
- package/dist/ct-design-safe-area-container.cjs.js +82 -0
- package/dist/ct-design-safe-area-container.cjs.js.map +1 -0
- package/dist/ct-design-safe-area-container.esm.js +67 -0
- package/dist/ct-design-safe-area-container.esm.js.map +1 -0
- package/dist/ct-design-safe-area-container.umd.js +83 -0
- package/dist/ct-design-safe-area-container.umd.js.map +1 -0
- package/dist/hooks/useSafeAreaInset/index.d.ts +4 -0
- package/dist/hooks/useSafeAreaInset/index.d.ts.map +1 -0
- package/dist/hooks/useSafeAreaInset/index.native.d.ts +4 -0
- package/dist/hooks/useSafeAreaInset/index.native.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/provider/hooks.d.ts +6 -0
- package/dist/provider/hooks.d.ts.map +1 -0
- package/dist/provider/index.d.ts +7 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/style.d.ts +11 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/type.d.ts +24 -0
- package/dist/type.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/SafeAreaContainer.native.tsx +42 -0
- package/src/SafeAreaContainer.tsx +40 -0
- package/src/hooks/useSafeAreaInset/index.native.ts +16 -0
- package/src/hooks/useSafeAreaInset/index.ts +18 -0
- package/src/index.ts +5 -0
- package/src/provider/hooks.ts +46 -0
- package/src/provider/index.tsx +35 -0
- package/src/style.ts +20 -0
- package/src/type.ts +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# SafeAreaContainer
|
|
2
|
+
|
|
3
|
+
A container that respects safe area boundaries on mobile devices.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @cleartrip/ct-design-safe-area-container
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @cleartrip/ct-design-safe-area-container
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Peer dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Required for all targets
|
|
19
|
+
npm install react
|
|
20
|
+
|
|
21
|
+
# Web only
|
|
22
|
+
npm install react-dom
|
|
23
|
+
|
|
24
|
+
# React Native only
|
|
25
|
+
npm install react-native
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Basic
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { SafeAreaContainer } from '@cleartrip/ct-design-safe-area-container';
|
|
36
|
+
|
|
37
|
+
function Example() {
|
|
38
|
+
return (
|
|
39
|
+
<SafeAreaContainer>
|
|
40
|
+
{/* Basic usage */}
|
|
41
|
+
</SafeAreaContainer>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Props
|
|
49
|
+
|
|
50
|
+
| Prop | Type | Default | Required | Description |
|
|
51
|
+
|------|------|---------|----------|-------------|
|
|
52
|
+
| `children` | `ReactNode` | — | ✅ Yes | Content rendered inside the safe-area padded wrapper. |
|
|
53
|
+
| `styleConfig` | `SafeAreaContainerStyleConfigProps` | — | No | Optional style overrides applied after the computed safe-area |
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Accessibility
|
|
59
|
+
|
|
60
|
+
- The component follows accessibility best practices
|
|
61
|
+
- Ensure proper ARIA attributes are provided where needed
|
|
62
|
+
- Test with screen readers to ensure usability
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Migration
|
|
67
|
+
|
|
68
|
+
If migrating from a previous version:
|
|
69
|
+
|
|
70
|
+
```diff
|
|
71
|
+
- import { SafeAreaContainer } from 'yagami/core/components';
|
|
72
|
+
+ import { SafeAreaContainer } from '@cleartrip/ct-design-safe-area-container';
|
|
73
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SafeAreaContainer.d.ts","sourceRoot":"","sources":["../packages/components/SafeAreaContainer/src/SafeAreaContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAY5C,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAkBnD,CAAC;AAIF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SafeAreaContainer.native.d.ts","sourceRoot":"","sources":["../packages/components/SafeAreaContainer/src/SafeAreaContainer.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAY5C,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAkBnD,CAAC;AAIF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("@cleartrip/ct-design-style-manager"),r=require("react"),s=require("react-native");function n(e){return e&&e.__esModule?e:{default:e}}var a=n(r);const o=({insets:e})=>{var t,r,s;return{paddingTop:null!==(t=e.top)&&void 0!==t?t:0,paddingBottom:0,paddingLeft:null!==(r=e.left)&&void 0!==r?r:0,paddingRight:null!==(s=e.right)&&void 0!==s?s:0,flex:1}},i=()=>({top:0,bottom:0,left:0,right:0}),l=({children:r,styleConfig:s={}})=>{const n={top:0,bottom:0,left:0,right:0},a=t.useStyles(()=>({root:o({insets:n})}),[n]),{root:i=[]}=s||{},l=t.useWebMergeStyles([a.root,...i],[a.root,i]);return e.jsx("div",{className:l,children:r})};l.displayName="SafeAreaContainer";const u={},d=r.createContext({insets:u});exports.DEFAULT_INSETS=u,exports.SafeAreaContainer=l,exports.SafeAreaContext=d,exports.SafeAreaProvider=({children:t,initialMetrics:n=u})=>{const[o,i]=a.default.useState(n),l=r.useCallback(e=>{i(e)},[]);return e.jsx(s.SafeAreaView,{children:e.jsx(d.Provider,{value:{insets:o,handleInsets:l},children:t})})},exports.getSafeAreaContainerStyles=o,exports.useGetSafeAreaInsets=()=>{const{insets:e}=r.useContext(d);return e},exports.useHandleSafeAreaInsets=()=>{const{handleInsets:e}=r.useContext(d);return e},exports.useSafeArea=()=>r.useContext(d),exports.useSafeAreaInset=i,exports.useSetSafeAreaInsets=(e,t)=>{const{handleInsets:s}=r.useContext(d);r.useEffect(()=>(null==s||s({top:e,bottom:t}),()=>{null==s||s(u)}),[s,e,t])};
|
|
2
|
+
//# sourceMappingURL=ct-design-safe-area-container.browser.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct-design-safe-area-container.browser.cjs.js","sources":["../packages/components/SafeAreaContainer/src/style.ts","../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.ts","../packages/components/SafeAreaContainer/src/SafeAreaContainer.tsx","../packages/components/SafeAreaContainer/src/provider/hooks.ts","../packages/components/SafeAreaContainer/src/provider/index.tsx"],"sourcesContent":[null,null,null,null,null],"names":["getSafeAreaContainerStyles","insets","paddingTop","_a","top","paddingBottom","paddingLeft","_b","left","paddingRight","_c","right","flex","useSafeAreaInset","bottom","SafeAreaContainer","children","styleConfig","containerStyles","useStyles","root","customRootStyles","mergedRootStyles","useWebMergeStyles","_jsx","className","displayName","DEFAULT_INSETS","SafeAreaContext","createContext","initialMetrics","setInsets","React","useState","handleInsets","useCallback","newInsets","SafeAreaView","Provider","value","useContext","useEffect"],"mappings":"iNAWaA,EAA6B,EAAGC,uBAC3C,MAAO,CACLC,mBAAYC,EAAAF,EAAOG,mBAAO,EAC1BC,cAAe,EACfC,oBAAaC,EAAAN,EAAOO,oBAAQ,EAC5BC,qBAAcC,EAAAT,EAAOU,qBAAS,EAC9BC,KAAM,ICTJC,EAAmB,KAChB,CACLT,IAAK,EACLU,OAAQ,EACRN,KAAM,EACNG,MAAO,ICILI,EAAkD,EAAGC,WAAUC,cAAc,CAAE,MACnF,MAAMhB,EDTC,CACLG,IAAK,EACLU,OAAQ,EACRN,KAAM,EACNG,MAAO,GCOHO,EAAkBC,EAAAA,UACtB,KAAO,CACLC,KAAMpB,EAA2B,CAAEC,aAErC,CAACA,KAGKmB,KAAMC,EAAmB,IAAOJ,GAAe,CAAA,EAEjDK,EAAmBC,EAAAA,kBACvB,CAACL,EAAgBE,QAASC,GAC1B,CAACH,EAAgBE,KAAMC,IAGzB,OAAOG,EAAAA,WAAKC,UAAWH,EAAmBN,SAAAA,KAG5CD,EAAkBW,YAAc,oBC5BnB,MCHAC,EAAiC,CAAG,EAEpCC,EAAkBC,EAAaA,cAAsB,CAAE5B,OAAQ0B,4GAYf,EAAGX,WAAUc,iBAAiBH,MACzF,MAAO1B,EAAQ8B,GAAaC,EAAAA,QAAMC,SAAyBH,GAErDI,EAAeC,cAAaC,IAChCL,EAAUK,IACT,IAEH,OACEZ,EAAAA,IAACa,EAAAA,aAAY,CAAArB,SACXQ,MAACI,EAAgBU,SAAS,CAAAC,MAAO,CAAEtC,SAAQiC,yBAAiBlB,yEDb9B,KAClC,MAAMf,OAAEA,GAAWuC,EAAUA,WAAsBZ,GACnD,OAAO3B,mCAQ8B,KACrC,MAAMiC,aAAEA,GAAiBM,EAAUA,WAAsBZ,GACzD,OAAOM,uBAnBkB,IAAMM,EAAUA,WAAsBZ,2DA2B7B,CAACxB,EAAcU,KACjD,MAAMoB,aAAEA,GAAiBM,EAAUA,WAAsBZ,GAEzDa,EAAAA,UAAU,KACRP,SAAAA,EAAe,CAAE9B,MAAKU,WACf,KACLoB,SAAAA,EAAeP,KAEhB,CAACO,EAAc9B,EAAKU"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import{useStyles as e,useWebMergeStyles as n}from"@cleartrip/ct-design-style-manager";import r,{useContext as o,useEffect as i,createContext as s,useCallback as l}from"react";import{SafeAreaView as a}from"react-native";const d=({insets:t})=>{var e,n,r;return{paddingTop:null!==(e=t.top)&&void 0!==e?e:0,paddingBottom:0,paddingLeft:null!==(n=t.left)&&void 0!==n?n:0,paddingRight:null!==(r=t.right)&&void 0!==r?r:0,flex:1}},c=()=>({top:0,bottom:0,left:0,right:0}),m=({children:r,styleConfig:o={}})=>{const i={top:0,bottom:0,left:0,right:0},s=e(()=>({root:d({insets:i})}),[i]),{root:l=[]}=o||{},a=n([s.root,...l],[s.root,l]);return t("div",{className:a,children:r})};m.displayName="SafeAreaContainer";const p=()=>o(v),u=()=>{const{insets:t}=o(v);return t},h=()=>{const{handleInsets:t}=o(v);return t},f=(t,e)=>{const{handleInsets:n}=o(v);i(()=>(null==n||n({top:t,bottom:e}),()=>{null==n||n(g)}),[n,t,e])},g={},v=s({insets:g}),b=({children:e,initialMetrics:n=g})=>{const[o,i]=r.useState(n),s=l(t=>{i(t)},[]);return t(a,{children:t(v.Provider,{value:{insets:o,handleInsets:s},children:e})})};export{g as DEFAULT_INSETS,m as SafeAreaContainer,v as SafeAreaContext,b as SafeAreaProvider,d as getSafeAreaContainerStyles,u as useGetSafeAreaInsets,h as useHandleSafeAreaInsets,p as useSafeArea,c as useSafeAreaInset,f as useSetSafeAreaInsets};
|
|
2
|
+
//# sourceMappingURL=ct-design-safe-area-container.browser.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct-design-safe-area-container.browser.esm.js","sources":["../packages/components/SafeAreaContainer/src/style.ts","../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.ts","../packages/components/SafeAreaContainer/src/SafeAreaContainer.tsx","../packages/components/SafeAreaContainer/src/provider/hooks.ts","../packages/components/SafeAreaContainer/src/provider/index.tsx"],"sourcesContent":[null,null,null,null,null],"names":["getSafeAreaContainerStyles","insets","paddingTop","_a","top","paddingBottom","paddingLeft","_b","left","paddingRight","_c","right","flex","useSafeAreaInset","bottom","SafeAreaContainer","children","styleConfig","containerStyles","useStyles","root","customRootStyles","mergedRootStyles","useWebMergeStyles","_jsx","className","displayName","useSafeArea","useContext","SafeAreaContext","useGetSafeAreaInsets","useHandleSafeAreaInsets","handleInsets","useSetSafeAreaInsets","useEffect","DEFAULT_INSETS","createContext","SafeAreaProvider","initialMetrics","setInsets","React","useState","useCallback","newInsets","SafeAreaView","Provider","value"],"mappings":"yQAWaA,EAA6B,EAAGC,uBAC3C,MAAO,CACLC,mBAAYC,EAAAF,EAAOG,mBAAO,EAC1BC,cAAe,EACfC,oBAAaC,EAAAN,EAAOO,oBAAQ,EAC5BC,qBAAcC,EAAAT,EAAOU,qBAAS,EAC9BC,KAAM,ICTJC,EAAmB,KAChB,CACLT,IAAK,EACLU,OAAQ,EACRN,KAAM,EACNG,MAAO,ICILI,EAAkD,EAAGC,WAAUC,cAAc,CAAE,MACnF,MAAMhB,EDTC,CACLG,IAAK,EACLU,OAAQ,EACRN,KAAM,EACNG,MAAO,GCOHO,EAAkBC,EACtB,KAAO,CACLC,KAAMpB,EAA2B,CAAEC,aAErC,CAACA,KAGKmB,KAAMC,EAAmB,IAAOJ,GAAe,CAAA,EAEjDK,EAAmBC,EACvB,CAACL,EAAgBE,QAASC,GAC1B,CAACH,EAAgBE,KAAMC,IAGzB,OAAOG,SAAKC,UAAWH,EAAmBN,SAAAA,KAG5CD,EAAkBW,YAAc,oBC5BnB,MAAAC,EAAc,IAAMC,EAAgCC,GAOpDC,EAAuB,KAClC,MAAM7B,OAAEA,GAAW2B,EAAgCC,GACnD,OAAO5B,GAQI8B,EAA0B,KACrC,MAAMC,aAAEA,GAAiBJ,EAAgCC,GACzD,OAAOG,GAQIC,EAAuB,CAAC7B,EAAcU,KACjD,MAAMkB,aAAEA,GAAiBJ,EAAgCC,GAEzDK,EAAU,KACRF,SAAAA,EAAe,CAAE5B,MAAKU,WACf,KACLkB,SAAAA,EAAeG,KAEhB,CAACH,EAAc5B,EAAKU,KCtCZqB,EAAiC,CAAG,EAEpCN,EAAkBO,EAAmC,CAAEnC,OAAQkC,IAY/DE,EAAgD,EAAGrB,WAAUsB,iBAAiBH,MACzF,MAAOlC,EAAQsC,GAAaC,EAAMC,SAAyBH,GAErDN,EAAeU,EAAaC,IAChCJ,EAAUI,IACT,IAEH,OACEnB,EAACoB,EAAY,CAAA5B,SACXQ,EAACK,EAAgBgB,SAAS,CAAAC,MAAO,CAAE7C,SAAQ+B,yBAAiBhB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var ctDesignStyleManager = require('@cleartrip/ct-design-style-manager');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var reactNative = require('react-native');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
11
|
+
|
|
12
|
+
const getSafeAreaContainerStyles = ({ insets }) => {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
return {
|
|
15
|
+
paddingTop: (_a = insets.top) !== null && _a !== void 0 ? _a : 0,
|
|
16
|
+
paddingBottom: 0,
|
|
17
|
+
paddingLeft: (_b = insets.left) !== null && _b !== void 0 ? _b : 0,
|
|
18
|
+
paddingRight: (_c = insets.right) !== null && _c !== void 0 ? _c : 0,
|
|
19
|
+
flex: 1,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const useSafeAreaInset = () => {
|
|
24
|
+
return {
|
|
25
|
+
top: 0,
|
|
26
|
+
bottom: 0,
|
|
27
|
+
left: 0,
|
|
28
|
+
right: 0,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const SafeAreaContainer = ({ children, styleConfig = {} }) => {
|
|
33
|
+
const insets = useSafeAreaInset();
|
|
34
|
+
const containerStyles = ctDesignStyleManager.useStyles(() => ({
|
|
35
|
+
root: getSafeAreaContainerStyles({ insets }),
|
|
36
|
+
}), [insets]);
|
|
37
|
+
const { root: customRootStyles = [] } = styleConfig || {};
|
|
38
|
+
const mergedRootStyles = ctDesignStyleManager.useWebMergeStyles([containerStyles.root, ...customRootStyles], [containerStyles.root, customRootStyles]);
|
|
39
|
+
return jsxRuntime.jsx("div", { className: mergedRootStyles, children: children });
|
|
40
|
+
};
|
|
41
|
+
SafeAreaContainer.displayName = 'SafeAreaContainer';
|
|
42
|
+
|
|
43
|
+
const useSafeArea = () => React.useContext(SafeAreaContext);
|
|
44
|
+
const useGetSafeAreaInsets = () => {
|
|
45
|
+
const { insets } = React.useContext(SafeAreaContext);
|
|
46
|
+
return insets;
|
|
47
|
+
};
|
|
48
|
+
const useHandleSafeAreaInsets = () => {
|
|
49
|
+
const { handleInsets } = React.useContext(SafeAreaContext);
|
|
50
|
+
return handleInsets;
|
|
51
|
+
};
|
|
52
|
+
const useSetSafeAreaInsets = (top, bottom) => {
|
|
53
|
+
const { handleInsets } = React.useContext(SafeAreaContext);
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
handleInsets === null || handleInsets === void 0 ? void 0 : handleInsets({ top, bottom });
|
|
56
|
+
return () => {
|
|
57
|
+
handleInsets === null || handleInsets === void 0 ? void 0 : handleInsets(DEFAULT_INSETS);
|
|
58
|
+
};
|
|
59
|
+
}, [handleInsets, top, bottom]);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const DEFAULT_INSETS = {};
|
|
63
|
+
const SafeAreaContext = React.createContext({ insets: DEFAULT_INSETS });
|
|
64
|
+
const SafeAreaProvider = ({ children, initialMetrics = DEFAULT_INSETS }) => {
|
|
65
|
+
const [insets, setInsets] = React__default.default.useState(initialMetrics);
|
|
66
|
+
const handleInsets = React.useCallback((newInsets) => {
|
|
67
|
+
setInsets(newInsets);
|
|
68
|
+
}, []);
|
|
69
|
+
return (jsxRuntime.jsx(reactNative.SafeAreaView, { children: jsxRuntime.jsx(SafeAreaContext.Provider, { value: { insets, handleInsets }, children: children }) }));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
exports.DEFAULT_INSETS = DEFAULT_INSETS;
|
|
73
|
+
exports.SafeAreaContainer = SafeAreaContainer;
|
|
74
|
+
exports.SafeAreaContext = SafeAreaContext;
|
|
75
|
+
exports.SafeAreaProvider = SafeAreaProvider;
|
|
76
|
+
exports.getSafeAreaContainerStyles = getSafeAreaContainerStyles;
|
|
77
|
+
exports.useGetSafeAreaInsets = useGetSafeAreaInsets;
|
|
78
|
+
exports.useHandleSafeAreaInsets = useHandleSafeAreaInsets;
|
|
79
|
+
exports.useSafeArea = useSafeArea;
|
|
80
|
+
exports.useSafeAreaInset = useSafeAreaInset;
|
|
81
|
+
exports.useSetSafeAreaInsets = useSetSafeAreaInsets;
|
|
82
|
+
//# sourceMappingURL=ct-design-safe-area-container.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct-design-safe-area-container.cjs.js","sources":["../packages/components/SafeAreaContainer/src/style.ts","../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.ts","../packages/components/SafeAreaContainer/src/SafeAreaContainer.tsx","../packages/components/SafeAreaContainer/src/provider/hooks.ts","../packages/components/SafeAreaContainer/src/provider/index.tsx"],"sourcesContent":[null,null,null,null,null],"names":["useStyles","useWebMergeStyles","_jsx","useContext","useEffect","createContext","React","useCallback","SafeAreaView"],"mappings":"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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
3
|
+
import React, { useContext, useEffect, createContext, useCallback } from 'react';
|
|
4
|
+
import { SafeAreaView } from 'react-native';
|
|
5
|
+
|
|
6
|
+
const getSafeAreaContainerStyles = ({ insets }) => {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
return {
|
|
9
|
+
paddingTop: (_a = insets.top) !== null && _a !== void 0 ? _a : 0,
|
|
10
|
+
paddingBottom: 0,
|
|
11
|
+
paddingLeft: (_b = insets.left) !== null && _b !== void 0 ? _b : 0,
|
|
12
|
+
paddingRight: (_c = insets.right) !== null && _c !== void 0 ? _c : 0,
|
|
13
|
+
flex: 1,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const useSafeAreaInset = () => {
|
|
18
|
+
return {
|
|
19
|
+
top: 0,
|
|
20
|
+
bottom: 0,
|
|
21
|
+
left: 0,
|
|
22
|
+
right: 0,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const SafeAreaContainer = ({ children, styleConfig = {} }) => {
|
|
27
|
+
const insets = useSafeAreaInset();
|
|
28
|
+
const containerStyles = useStyles(() => ({
|
|
29
|
+
root: getSafeAreaContainerStyles({ insets }),
|
|
30
|
+
}), [insets]);
|
|
31
|
+
const { root: customRootStyles = [] } = styleConfig || {};
|
|
32
|
+
const mergedRootStyles = useWebMergeStyles([containerStyles.root, ...customRootStyles], [containerStyles.root, customRootStyles]);
|
|
33
|
+
return jsx("div", { className: mergedRootStyles, children: children });
|
|
34
|
+
};
|
|
35
|
+
SafeAreaContainer.displayName = 'SafeAreaContainer';
|
|
36
|
+
|
|
37
|
+
const useSafeArea = () => useContext(SafeAreaContext);
|
|
38
|
+
const useGetSafeAreaInsets = () => {
|
|
39
|
+
const { insets } = useContext(SafeAreaContext);
|
|
40
|
+
return insets;
|
|
41
|
+
};
|
|
42
|
+
const useHandleSafeAreaInsets = () => {
|
|
43
|
+
const { handleInsets } = useContext(SafeAreaContext);
|
|
44
|
+
return handleInsets;
|
|
45
|
+
};
|
|
46
|
+
const useSetSafeAreaInsets = (top, bottom) => {
|
|
47
|
+
const { handleInsets } = useContext(SafeAreaContext);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
handleInsets === null || handleInsets === void 0 ? void 0 : handleInsets({ top, bottom });
|
|
50
|
+
return () => {
|
|
51
|
+
handleInsets === null || handleInsets === void 0 ? void 0 : handleInsets(DEFAULT_INSETS);
|
|
52
|
+
};
|
|
53
|
+
}, [handleInsets, top, bottom]);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const DEFAULT_INSETS = {};
|
|
57
|
+
const SafeAreaContext = createContext({ insets: DEFAULT_INSETS });
|
|
58
|
+
const SafeAreaProvider = ({ children, initialMetrics = DEFAULT_INSETS }) => {
|
|
59
|
+
const [insets, setInsets] = React.useState(initialMetrics);
|
|
60
|
+
const handleInsets = useCallback((newInsets) => {
|
|
61
|
+
setInsets(newInsets);
|
|
62
|
+
}, []);
|
|
63
|
+
return (jsx(SafeAreaView, { children: jsx(SafeAreaContext.Provider, { value: { insets, handleInsets }, children: children }) }));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { DEFAULT_INSETS, SafeAreaContainer, SafeAreaContext, SafeAreaProvider, getSafeAreaContainerStyles, useGetSafeAreaInsets, useHandleSafeAreaInsets, useSafeArea, useSafeAreaInset, useSetSafeAreaInsets };
|
|
67
|
+
//# sourceMappingURL=ct-design-safe-area-container.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct-design-safe-area-container.esm.js","sources":["../packages/components/SafeAreaContainer/src/style.ts","../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.ts","../packages/components/SafeAreaContainer/src/SafeAreaContainer.tsx","../packages/components/SafeAreaContainer/src/provider/hooks.ts","../packages/components/SafeAreaContainer/src/provider/index.tsx"],"sourcesContent":[null,null,null,null,null],"names":["_jsx"],"mappings":";;;;;MAWa,0BAA0B,GAAG,CAAC,EAAE,MAAM,EAA8B,KAAI;;IACnF,OAAO;AACL,QAAA,UAAU,EAAE,CAAA,EAAA,GAAA,MAAM,CAAC,GAAG,mCAAI,CAAC;AAC3B,QAAA,aAAa,EAAE,CAAC;AAChB,QAAA,WAAW,EAAE,CAAA,EAAA,GAAA,MAAM,CAAC,IAAI,mCAAI,CAAC;AAC7B,QAAA,YAAY,EAAE,CAAA,EAAA,GAAA,MAAM,CAAC,KAAK,mCAAI,CAAC;AAC/B,QAAA,IAAI,EAAE,CAAC;KACR,CAAC;AACJ;;ACXM,MAAA,gBAAgB,GAAG,MAA+B;IACtD,OAAO;AACL,QAAA,GAAG,EAAE,CAAC;AACN,QAAA,MAAM,EAAE,CAAC;AACT,QAAA,IAAI,EAAE,CAAC;AACP,QAAA,KAAK,EAAE,CAAC;KACT,CAAC;AACJ;;ACEM,MAAA,iBAAiB,GAAiC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,EAAE,KAAI;AACzF,IAAA,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAElC,IAAA,MAAM,eAAe,GAAG,SAAS,CAC/B,OAAO;AACL,QAAA,IAAI,EAAE,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAC;AAC7C,KAAA,CAAC,EACF,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,EAAE,EAAE,GAAG,WAAW,IAAI,EAAE,CAAC;IAE1D,MAAM,gBAAgB,GAAG,iBAAiB,CACxC,CAAC,eAAe,CAAC,IAAI,EAAE,GAAG,gBAAgB,CAAC,EAC3C,CAAC,eAAe,CAAC,IAAI,EAAE,gBAAgB,CAAC,CACzC,CAAC;AAEF,IAAA,OAAOA,aAAK,SAAS,EAAE,gBAAgB,EAAG,QAAA,EAAA,QAAQ,GAAO,CAAC;AAC5D,EAAE;AAEF,iBAAiB,CAAC,WAAW,GAAG,mBAAmB;;AC5BtC,MAAA,WAAW,GAAG,MAAM,UAAU,CAAsB,eAAe,EAAE;AAO3E,MAAM,oBAAoB,GAAG,MAAqB;IACvD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAsB,eAAe,CAAC,CAAC;AACpE,IAAA,OAAO,MAAM,CAAC;AAChB,EAAE;AAOK,MAAM,uBAAuB,GAAG,MAAK;IAC1C,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,CAAsB,eAAe,CAAC,CAAC;AAC1E,IAAA,OAAO,YAAY,CAAC;AACtB,EAAE;MAOW,oBAAoB,GAAG,CAAC,GAAY,EAAE,MAAe,KAAI;IACpE,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,CAAsB,eAAe,CAAC,CAAC;IAE1E,SAAS,CAAC,MAAK;QACb,YAAY,KAAA,IAAA,IAAZ,YAAY,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAZ,YAAY,CAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;AAChC,QAAA,OAAO,MAAK;AACV,YAAA,YAAY,aAAZ,YAAY,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAZ,YAAY,CAAG,cAAc,CAAC,CAAC;AACjC,SAAC,CAAC;KACH,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AAClC;;ACvCO,MAAM,cAAc,GAAmB,GAAG;AAE1C,MAAM,eAAe,GAAG,aAAa,CAAsB,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE;AAYvF,MAAM,gBAAgB,GAAgC,CAAC,EAAE,QAAQ,EAAE,cAAc,GAAG,cAAc,EAAE,KAAI;AAC7G,IAAA,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAiB,cAAc,CAAC,CAAC;AAE3E,IAAA,MAAM,YAAY,GAAG,WAAW,CAAC,CAAC,SAAyB,KAAI;QAC7D,SAAS,CAAC,SAAS,CAAC,CAAC;KACtB,EAAE,EAAE,CAAC,CAAC;IAEP,QACEA,IAAC,YAAY,EAAA,EAAA,QAAA,EACXA,IAAC,eAAe,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,YAAG,QAAQ,EAAA,CAA4B,EACnF,CAAA,EACf;AACJ;;;;"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('@cleartrip/ct-design-style-manager'), require('react'), require('react-native')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', '@cleartrip/ct-design-style-manager', 'react', 'react-native'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemSafeAreaContainer = {}, global.jsxRuntime, global.ctDesignStyleManager, global.React, global.reactNative));
|
|
5
|
+
})(this, (function (exports, jsxRuntime, ctDesignStyleManager, React, reactNative) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
10
|
+
|
|
11
|
+
const getSafeAreaContainerStyles = ({ insets }) => {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
return {
|
|
14
|
+
paddingTop: (_a = insets.top) !== null && _a !== void 0 ? _a : 0,
|
|
15
|
+
paddingBottom: 0,
|
|
16
|
+
paddingLeft: (_b = insets.left) !== null && _b !== void 0 ? _b : 0,
|
|
17
|
+
paddingRight: (_c = insets.right) !== null && _c !== void 0 ? _c : 0,
|
|
18
|
+
flex: 1,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const useSafeAreaInset = () => {
|
|
23
|
+
return {
|
|
24
|
+
top: 0,
|
|
25
|
+
bottom: 0,
|
|
26
|
+
left: 0,
|
|
27
|
+
right: 0,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const SafeAreaContainer = ({ children, styleConfig = {} }) => {
|
|
32
|
+
const insets = useSafeAreaInset();
|
|
33
|
+
const containerStyles = ctDesignStyleManager.useStyles(() => ({
|
|
34
|
+
root: getSafeAreaContainerStyles({ insets }),
|
|
35
|
+
}), [insets]);
|
|
36
|
+
const { root: customRootStyles = [] } = styleConfig || {};
|
|
37
|
+
const mergedRootStyles = ctDesignStyleManager.useWebMergeStyles([containerStyles.root, ...customRootStyles], [containerStyles.root, customRootStyles]);
|
|
38
|
+
return jsxRuntime.jsx("div", { className: mergedRootStyles, children: children });
|
|
39
|
+
};
|
|
40
|
+
SafeAreaContainer.displayName = 'SafeAreaContainer';
|
|
41
|
+
|
|
42
|
+
const useSafeArea = () => React.useContext(SafeAreaContext);
|
|
43
|
+
const useGetSafeAreaInsets = () => {
|
|
44
|
+
const { insets } = React.useContext(SafeAreaContext);
|
|
45
|
+
return insets;
|
|
46
|
+
};
|
|
47
|
+
const useHandleSafeAreaInsets = () => {
|
|
48
|
+
const { handleInsets } = React.useContext(SafeAreaContext);
|
|
49
|
+
return handleInsets;
|
|
50
|
+
};
|
|
51
|
+
const useSetSafeAreaInsets = (top, bottom) => {
|
|
52
|
+
const { handleInsets } = React.useContext(SafeAreaContext);
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
handleInsets === null || handleInsets === void 0 ? void 0 : handleInsets({ top, bottom });
|
|
55
|
+
return () => {
|
|
56
|
+
handleInsets === null || handleInsets === void 0 ? void 0 : handleInsets(DEFAULT_INSETS);
|
|
57
|
+
};
|
|
58
|
+
}, [handleInsets, top, bottom]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const DEFAULT_INSETS = {};
|
|
62
|
+
const SafeAreaContext = React.createContext({ insets: DEFAULT_INSETS });
|
|
63
|
+
const SafeAreaProvider = ({ children, initialMetrics = DEFAULT_INSETS }) => {
|
|
64
|
+
const [insets, setInsets] = React__default.default.useState(initialMetrics);
|
|
65
|
+
const handleInsets = React.useCallback((newInsets) => {
|
|
66
|
+
setInsets(newInsets);
|
|
67
|
+
}, []);
|
|
68
|
+
return (jsxRuntime.jsx(reactNative.SafeAreaView, { children: jsxRuntime.jsx(SafeAreaContext.Provider, { value: { insets, handleInsets }, children: children }) }));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
exports.DEFAULT_INSETS = DEFAULT_INSETS;
|
|
72
|
+
exports.SafeAreaContainer = SafeAreaContainer;
|
|
73
|
+
exports.SafeAreaContext = SafeAreaContext;
|
|
74
|
+
exports.SafeAreaProvider = SafeAreaProvider;
|
|
75
|
+
exports.getSafeAreaContainerStyles = getSafeAreaContainerStyles;
|
|
76
|
+
exports.useGetSafeAreaInsets = useGetSafeAreaInsets;
|
|
77
|
+
exports.useHandleSafeAreaInsets = useHandleSafeAreaInsets;
|
|
78
|
+
exports.useSafeArea = useSafeArea;
|
|
79
|
+
exports.useSafeAreaInset = useSafeAreaInset;
|
|
80
|
+
exports.useSetSafeAreaInsets = useSetSafeAreaInsets;
|
|
81
|
+
|
|
82
|
+
}));
|
|
83
|
+
//# sourceMappingURL=ct-design-safe-area-container.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct-design-safe-area-container.umd.js","sources":["../packages/components/SafeAreaContainer/src/style.ts","../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.ts","../packages/components/SafeAreaContainer/src/SafeAreaContainer.tsx","../packages/components/SafeAreaContainer/src/provider/hooks.ts","../packages/components/SafeAreaContainer/src/provider/index.tsx"],"sourcesContent":[null,null,null,null,null],"names":["useStyles","useWebMergeStyles","_jsx","useContext","useEffect","createContext","React","useCallback","SafeAreaView"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQjD,QAAA,MAAM,gBAAgB,QAAO,QAAQ,CAAC,cAAc,CAOnD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../../packages/components/SafeAreaContainer/src/hooks/useSafeAreaInset/index.native.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQjD,QAAA,MAAM,gBAAgB,QAAO,QAAQ,CAAC,cAAc,CAGnD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as SafeAreaContainer } from './SafeAreaContainer';
|
|
2
|
+
export { default as useSafeAreaInset } from './hooks/useSafeAreaInset';
|
|
3
|
+
export * from './provider';
|
|
4
|
+
export * from './type';
|
|
5
|
+
export { getSafeAreaContainerStyles } from './style';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/components/SafeAreaContainer/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACvE,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SafeAreaContextType, SafeAreaInsets } from '../type';
|
|
2
|
+
export declare const useSafeArea: () => SafeAreaContextType;
|
|
3
|
+
export declare const useGetSafeAreaInsets: () => SafeAreaInsets;
|
|
4
|
+
export declare const useHandleSafeAreaInsets: () => ((insets: SafeAreaInsets) => void) | undefined;
|
|
5
|
+
export declare const useSetSafeAreaInsets: (top?: number, bottom?: number) => void;
|
|
6
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../packages/components/SafeAreaContainer/src/provider/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMnE,eAAO,MAAM,WAAW,2BAAyD,CAAC;AAOlF,eAAO,MAAM,oBAAoB,QAAO,cAGvC,CAAC;AAOF,eAAO,MAAM,uBAAuB,sDAGnC,CAAC;AAOF,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,SASjE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ISafeAreaProvider, SafeAreaContextType, SafeAreaInsets } from '../type';
|
|
3
|
+
export declare const DEFAULT_INSETS: SafeAreaInsets;
|
|
4
|
+
export declare const SafeAreaContext: React.Context<SafeAreaContextType>;
|
|
5
|
+
export declare const SafeAreaProvider: React.FC<ISafeAreaProvider>;
|
|
6
|
+
export { useSafeArea, useGetSafeAreaInsets, useHandleSafeAreaInsets, useSetSafeAreaInsets } from './hooks';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/components/SafeAreaContainer/src/provider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAI1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEtF,eAAO,MAAM,cAAc,EAAE,cAAmB,CAAC;AAEjD,eAAO,MAAM,eAAe,oCAAiE,CAAC;AAY9F,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAYxD,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SafeAreaInsets } from './type';
|
|
2
|
+
export declare const getSafeAreaContainerStyles: ({ insets }: {
|
|
3
|
+
insets: SafeAreaInsets;
|
|
4
|
+
}) => {
|
|
5
|
+
paddingTop: number;
|
|
6
|
+
paddingBottom: number;
|
|
7
|
+
paddingLeft: number;
|
|
8
|
+
paddingRight: number;
|
|
9
|
+
flex: number;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/SafeAreaContainer/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAWxC,eAAO,MAAM,0BAA0B,GAAI,YAAY;IAAE,MAAM,EAAE,cAAc,CAAA;CAAE;;;;;;CAQhF,CAAC"}
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { Styles, ViewStyle } from '@cleartrip/ct-design-types';
|
|
3
|
+
export interface SafeAreaInsets {
|
|
4
|
+
top?: number;
|
|
5
|
+
bottom?: number;
|
|
6
|
+
left?: number;
|
|
7
|
+
right?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SafeAreaContextType {
|
|
10
|
+
insets: SafeAreaInsets;
|
|
11
|
+
handleInsets?: (insets: SafeAreaInsets) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface ISafeAreaProvider {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
initialMetrics?: SafeAreaInsets;
|
|
16
|
+
}
|
|
17
|
+
export interface SafeAreaContainerStyleConfigProps {
|
|
18
|
+
root?: Styles[] | ViewStyle[];
|
|
19
|
+
}
|
|
20
|
+
export interface ISafeAreaContainer {
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
styleConfig?: SafeAreaContainerStyleConfigProps;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/SafeAreaContainer/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAOpE,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,cAAc,CAAC;IACvB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;CACjD;AAKD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAC;IAKpB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAOD,MAAM,WAAW,iCAAiC;IAIhD,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;CAC/B;AAKD,MAAM,WAAW,kBAAkB;IAIjC,QAAQ,EAAE,SAAS,CAAC;IAMpB,WAAW,CAAC,EAAE,iCAAiC,CAAC;CACjD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cleartrip/ct-design-safe-area-container",
|
|
3
|
+
"version": "4.0.0-SNAPSHOT-test.0",
|
|
4
|
+
"description": "SafeAreaContainer component — applies device safe-area insets via the ct-design-style-manager hooks on web and React Native.",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/ct-design-safe-area-container.cjs.js",
|
|
7
|
+
"jsnext:main": "dist/ct-design-safe-area-container.esm.js",
|
|
8
|
+
"module": "dist/ct-design-safe-area-container.esm.js",
|
|
9
|
+
"react-native": "src/index.ts",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/ct-design-safe-area-container.d.ts",
|
|
14
|
+
"import": "./dist/ct-design-safe-area-container.esm.js",
|
|
15
|
+
"default": "./dist/ct-design-safe-area-container.cjs.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"browser": {
|
|
19
|
+
"./dist/ct-design-safe-area-container.esm.js": "./dist/ct-design-safe-area-container.browser.esm.js",
|
|
20
|
+
"./dist/ct-design-safe-area-container.cjs.js": "./dist/ct-design-safe-area-container.browser.cjs.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@cleartrip/ct-design-style-manager": "4.0.0-SNAPSHOT-test.0",
|
|
28
|
+
"@cleartrip/ct-design-types": "4.0.0-SNAPSHOT-test.0",
|
|
29
|
+
"@cleartrip/ct-design-theme": "4.0.0-SNAPSHOT-test.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@emotion/babel-plugin": "^11.12.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=16.8.0",
|
|
36
|
+
"react-dom": ">=16.8.0",
|
|
37
|
+
"react-native": "*",
|
|
38
|
+
"react-native-safe-area-context": "*"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"react-native": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"react-native-safe-area-context": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"author": "Mukund <balmukund.kumar@cleartrip.com>",
|
|
52
|
+
"license": "ISC",
|
|
53
|
+
"scripts": {
|
|
54
|
+
"watch-package": "rollup -c -w",
|
|
55
|
+
"build-package": "rollup -c",
|
|
56
|
+
"build-package:clean": "rm -rf dist && rollup -c",
|
|
57
|
+
"publish-package:local": "yalc publish"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
|
+
import { useStyles, useNativeMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
6
|
+
|
|
7
|
+
import { getSafeAreaContainerStyles } from './style';
|
|
8
|
+
import { ISafeAreaContainer } from './type';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* React Native implementation of SafeAreaContainer.
|
|
12
|
+
*
|
|
13
|
+
* Reads real device insets via `react-native-safe-area-context` and
|
|
14
|
+
* applies them as padding on a plain `<View>`. Styles flow through the
|
|
15
|
+
* style-manager (`useStyles` for dynamic inset-driven values,
|
|
16
|
+
* `useNativeMergeStyles` for merging consumer overrides) so the
|
|
17
|
+
* component has zero dependency on aldenui's Container or legacy
|
|
18
|
+
* `useStyles` hook.
|
|
19
|
+
*/
|
|
20
|
+
const SafeAreaContainer: React.FC<ISafeAreaContainer> = ({ children, styleConfig = {} }) => {
|
|
21
|
+
const insets = useSafeAreaInsets();
|
|
22
|
+
|
|
23
|
+
const containerStyles = useStyles(
|
|
24
|
+
() => ({
|
|
25
|
+
root: getSafeAreaContainerStyles({ insets }),
|
|
26
|
+
}),
|
|
27
|
+
[insets],
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const { root: rootStyles = [] } = styleConfig || {};
|
|
31
|
+
|
|
32
|
+
const mergedRootStyles = useNativeMergeStyles(
|
|
33
|
+
[containerStyles.root, ...rootStyles],
|
|
34
|
+
[containerStyles.root, styleConfig?.root],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return <View style={mergedRootStyles}>{children}</View>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
SafeAreaContainer.displayName = 'SafeAreaContainer';
|
|
41
|
+
|
|
42
|
+
export default SafeAreaContainer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
4
|
+
|
|
5
|
+
import { getSafeAreaContainerStyles } from './style';
|
|
6
|
+
import { ISafeAreaContainer } from './type';
|
|
7
|
+
import useSafeAreaInset from './hooks/useSafeAreaInset';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Web implementation of SafeAreaContainer.
|
|
11
|
+
*
|
|
12
|
+
* On the browser there is no true system safe-area (notch / home-bar), so
|
|
13
|
+
* `useSafeAreaInset` returns a zeroed inset object. The wrapper is still
|
|
14
|
+
* rendered as a plain semantic `<div>` styled via `useStyles` +
|
|
15
|
+
* `useWebMergeStyles` to stay consistent with the cross-platform
|
|
16
|
+
* contract documented in Migration.MD — no styled-components remain.
|
|
17
|
+
*/
|
|
18
|
+
const SafeAreaContainer: React.FC<ISafeAreaContainer> = ({ children, styleConfig = {} }) => {
|
|
19
|
+
const insets = useSafeAreaInset();
|
|
20
|
+
|
|
21
|
+
const containerStyles = useStyles(
|
|
22
|
+
() => ({
|
|
23
|
+
root: getSafeAreaContainerStyles({ insets }),
|
|
24
|
+
}),
|
|
25
|
+
[insets],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const { root: customRootStyles = [] } = styleConfig || {};
|
|
29
|
+
|
|
30
|
+
const mergedRootStyles = useWebMergeStyles(
|
|
31
|
+
[containerStyles.root, ...customRootStyles],
|
|
32
|
+
[containerStyles.root, customRootStyles],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return <div className={mergedRootStyles}>{children}</div>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
SafeAreaContainer.displayName = 'SafeAreaContainer';
|
|
39
|
+
|
|
40
|
+
export default SafeAreaContainer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
2
|
+
|
|
3
|
+
import type { SafeAreaInsets } from '../../type';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React Native build: delegates to react-native-safe-area-context and
|
|
7
|
+
* guards against the provider missing at the root of the tree by
|
|
8
|
+
* falling back to a zeroed inset object (identical to the legacy
|
|
9
|
+
* aldenui implementation).
|
|
10
|
+
*/
|
|
11
|
+
const useSafeAreaInset = (): Required<SafeAreaInsets> => {
|
|
12
|
+
const insets = useSafeAreaInsets();
|
|
13
|
+
return insets || { top: 0, bottom: 0, left: 0, right: 0 };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default useSafeAreaInset;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SafeAreaInsets } from '../../type';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web fallback: browsers do not expose per-edge system insets, so we
|
|
5
|
+
* return an all-zero inset object. This mirrors the behaviour of the
|
|
6
|
+
* original aldenui hook and keeps parity with the native build-time
|
|
7
|
+
* contract so platform-shared code never has to branch on `Platform`.
|
|
8
|
+
*/
|
|
9
|
+
const useSafeAreaInset = (): Required<SafeAreaInsets> => {
|
|
10
|
+
return {
|
|
11
|
+
top: 0,
|
|
12
|
+
bottom: 0,
|
|
13
|
+
left: 0,
|
|
14
|
+
right: 0,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default useSafeAreaInset;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_INSETS, SafeAreaContext } from './';
|
|
4
|
+
import type { SafeAreaContextType, SafeAreaInsets } from '../type';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the full SafeAreaContext value (insets + the updater). Use this
|
|
8
|
+
* when a component needs both read and write access to the provider.
|
|
9
|
+
*/
|
|
10
|
+
export const useSafeArea = () => useContext<SafeAreaContextType>(SafeAreaContext);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Convenience hook returning only the current `insets` slice of the
|
|
14
|
+
* context. Prefer this in read-only consumers to avoid re-rendering
|
|
15
|
+
* when the setter identity changes.
|
|
16
|
+
*/
|
|
17
|
+
export const useGetSafeAreaInsets = (): SafeAreaInsets => {
|
|
18
|
+
const { insets } = useContext<SafeAreaContextType>(SafeAreaContext);
|
|
19
|
+
return insets;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the context's inset setter. Useful when a descendant has
|
|
24
|
+
* measured its own safe area (for example from a layout event) and
|
|
25
|
+
* wants to propagate the value up for siblings to consume.
|
|
26
|
+
*/
|
|
27
|
+
export const useHandleSafeAreaInsets = () => {
|
|
28
|
+
const { handleInsets } = useContext<SafeAreaContextType>(SafeAreaContext);
|
|
29
|
+
return handleInsets;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Imperatively pushes a `{ top, bottom }` inset pair into the provider
|
|
34
|
+
* for the lifetime of the calling component. On unmount the context is
|
|
35
|
+
* reset to `DEFAULT_INSETS` so nothing leaks between screens.
|
|
36
|
+
*/
|
|
37
|
+
export const useSetSafeAreaInsets = (top?: number, bottom?: number) => {
|
|
38
|
+
const { handleInsets } = useContext<SafeAreaContextType>(SafeAreaContext);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
handleInsets?.({ top, bottom });
|
|
42
|
+
return () => {
|
|
43
|
+
handleInsets?.(DEFAULT_INSETS);
|
|
44
|
+
};
|
|
45
|
+
}, [handleInsets, top, bottom]);
|
|
46
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { createContext, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { SafeAreaView } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import type { ISafeAreaProvider, SafeAreaContextType, SafeAreaInsets } from '../type';
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_INSETS: SafeAreaInsets = {};
|
|
8
|
+
|
|
9
|
+
export const SafeAreaContext = createContext<SafeAreaContextType>({ insets: DEFAULT_INSETS });
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Web build of SafeAreaProvider.
|
|
13
|
+
*
|
|
14
|
+
* The web target does not have a real safe-area primitive, so we lean
|
|
15
|
+
* on React Native's `SafeAreaView` (which is rendered as a plain
|
|
16
|
+
* `<View>` on web via react-native-web) purely to preserve the API
|
|
17
|
+
* shape. The `SafeAreaContext.Provider` is the part that actually
|
|
18
|
+
* matters: descendants rely on it for read/write access to the
|
|
19
|
+
* in-memory inset object.
|
|
20
|
+
*/
|
|
21
|
+
export const SafeAreaProvider: React.FC<ISafeAreaProvider> = ({ children, initialMetrics = DEFAULT_INSETS }) => {
|
|
22
|
+
const [insets, setInsets] = React.useState<SafeAreaInsets>(initialMetrics);
|
|
23
|
+
|
|
24
|
+
const handleInsets = useCallback((newInsets: SafeAreaInsets) => {
|
|
25
|
+
setInsets(newInsets);
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<SafeAreaView>
|
|
30
|
+
<SafeAreaContext.Provider value={{ insets, handleInsets }}>{children}</SafeAreaContext.Provider>
|
|
31
|
+
</SafeAreaView>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { useSafeArea, useGetSafeAreaInsets, useHandleSafeAreaInsets, useSetSafeAreaInsets } from './hooks';
|
package/src/style.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SafeAreaInsets } from './type';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Produces the root style block for the SafeAreaContainer. Padding is
|
|
5
|
+
* driven entirely by the insets so the wrapper is a straight port of
|
|
6
|
+
* the legacy aldenui behavior:
|
|
7
|
+
* paddingTop = insets.top
|
|
8
|
+
* paddingBottom = 0 (match the original — bottom is intentionally ignored)
|
|
9
|
+
* paddingLeft = insets.left
|
|
10
|
+
* paddingRight = insets.right
|
|
11
|
+
*/
|
|
12
|
+
export const getSafeAreaContainerStyles = ({ insets }: { insets: SafeAreaInsets }) => {
|
|
13
|
+
return {
|
|
14
|
+
paddingTop: insets.top ?? 0,
|
|
15
|
+
paddingBottom: 0,
|
|
16
|
+
paddingLeft: insets.left ?? 0,
|
|
17
|
+
paddingRight: insets.right ?? 0,
|
|
18
|
+
flex: 1,
|
|
19
|
+
};
|
|
20
|
+
};
|
package/src/type.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Styles, ViewStyle } from '@cleartrip/ct-design-types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Safe-area insets for the four edges of the device viewport.
|
|
7
|
+
* Values correspond to the space required to avoid system UI (notch,
|
|
8
|
+
* home indicator, status bar, etc.) in density-independent pixels.
|
|
9
|
+
*/
|
|
10
|
+
export interface SafeAreaInsets {
|
|
11
|
+
top?: number;
|
|
12
|
+
bottom?: number;
|
|
13
|
+
left?: number;
|
|
14
|
+
right?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Shape of the SafeAreaContext value — exposes the current insets and
|
|
19
|
+
* an optional setter so descendants can push their measured values up.
|
|
20
|
+
*/
|
|
21
|
+
export interface SafeAreaContextType {
|
|
22
|
+
insets: SafeAreaInsets;
|
|
23
|
+
handleInsets?: (insets: SafeAreaInsets) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Props accepted by `SafeAreaProvider`.
|
|
28
|
+
*/
|
|
29
|
+
export interface ISafeAreaProvider {
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Insets to seed the provider with. Useful for SSR or tests where
|
|
33
|
+
* the platform cannot supply real measurements.
|
|
34
|
+
*/
|
|
35
|
+
initialMetrics?: SafeAreaInsets;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Style configuration for the SafeAreaContainer root element. Mirrors
|
|
40
|
+
* the pattern used by Container / Typography so consumers can override
|
|
41
|
+
* the default flex + padding block.
|
|
42
|
+
*/
|
|
43
|
+
export interface SafeAreaContainerStyleConfigProps {
|
|
44
|
+
/**
|
|
45
|
+
* Styles for the root wrapper element (web `<div>` or RN `View`).
|
|
46
|
+
*/
|
|
47
|
+
root?: Styles[] | ViewStyle[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Public props for the `SafeAreaContainer` component.
|
|
52
|
+
*/
|
|
53
|
+
export interface ISafeAreaContainer {
|
|
54
|
+
/**
|
|
55
|
+
* Content rendered inside the safe-area padded wrapper.
|
|
56
|
+
*/
|
|
57
|
+
children: ReactNode;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Optional style overrides applied after the computed safe-area
|
|
61
|
+
* padding so consumers can always win the cascade.
|
|
62
|
+
*/
|
|
63
|
+
styleConfig?: SafeAreaContainerStyleConfigProps;
|
|
64
|
+
}
|