@cleartrip/ct-design-conditional-wrap 4.0.0-TEST.1 → 4.1.0-SNAPSHOT-native-main.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/README.md +166 -0
- package/dist/ct-design-conditional-wrapper.browser.cjs.js +1 -1
- package/dist/ct-design-conditional-wrapper.browser.cjs.js.map +1 -1
- package/dist/ct-design-conditional-wrapper.browser.esm.js +1 -1
- package/dist/ct-design-conditional-wrapper.browser.esm.js.map +1 -1
- package/dist/ct-design-conditional-wrapper.cjs.js +2 -2
- package/dist/ct-design-conditional-wrapper.cjs.js.map +1 -1
- package/dist/ct-design-conditional-wrapper.esm.js +2 -3
- package/dist/ct-design-conditional-wrapper.esm.js.map +1 -1
- package/dist/ct-design-conditional-wrapper.umd.js +2 -2
- package/dist/ct-design-conditional-wrapper.umd.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +17 -4
- package/src/index.ts +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# ConditionalWrap
|
|
2
|
+
|
|
3
|
+
ConditionalWrap conditionally wraps children with a wrapper component based on a boolean condition.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @cleartrip/ct-design-conditional-wrap
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @cleartrip/ct-design-conditional-wrap
|
|
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 conditional wrapping
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import ConditionalWrap from '@cleartrip/ct-design-conditional-wrap';
|
|
36
|
+
|
|
37
|
+
function Example({ hasLink }: { hasLink: boolean }) {
|
|
38
|
+
return (
|
|
39
|
+
<ConditionalWrap
|
|
40
|
+
condition={hasLink}
|
|
41
|
+
wrap={(children) => <a href="/link">{children}</a>}
|
|
42
|
+
>
|
|
43
|
+
<span>This may or may not be wrapped in a link</span>
|
|
44
|
+
</ConditionalWrap>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Conditional styling wrapper
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
<ConditionalWrap
|
|
53
|
+
condition={isHighlighted}
|
|
54
|
+
wrap={(children) => (
|
|
55
|
+
<div style={{ backgroundColor: 'yellow', padding: 8 }}>
|
|
56
|
+
{children}
|
|
57
|
+
</div>
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
<div>Content that might be highlighted</div>
|
|
61
|
+
</ConditionalWrap>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Modal or dialog wrapper
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
<ConditionalWrap
|
|
68
|
+
condition={showInModal}
|
|
69
|
+
wrap={(children) => (
|
|
70
|
+
<div className="modal-overlay">
|
|
71
|
+
<div className="modal-content">
|
|
72
|
+
{children}
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
>
|
|
77
|
+
<div>Content that may appear in a modal</div>
|
|
78
|
+
</ConditionalWrap>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Props
|
|
84
|
+
|
|
85
|
+
| Prop | Type | Default | Required | Description |
|
|
86
|
+
|------|------|---------|----------|-------------|
|
|
87
|
+
| `condition` | `boolean` | — | Yes | Boolean condition that determines whether to apply the wrapper |
|
|
88
|
+
| `wrap` | `(component: ReactElement) => ReactElement` | — | Yes | Function that wraps the children when condition is true |
|
|
89
|
+
| `children` | `ReactElement` | — | Yes | The child element to conditionally wrap |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Use Cases
|
|
94
|
+
|
|
95
|
+
### Conditional Links
|
|
96
|
+
Wrap text in a link only when a URL is provided:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<ConditionalWrap
|
|
100
|
+
condition={!!url}
|
|
101
|
+
wrap={(children) => <a href={url}>{children}</a>}
|
|
102
|
+
>
|
|
103
|
+
<span>{linkText}</span>
|
|
104
|
+
</ConditionalWrap>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Conditional Tooltips
|
|
108
|
+
Add tooltips only when tooltip text exists:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<ConditionalWrap
|
|
112
|
+
condition={!!tooltipText}
|
|
113
|
+
wrap={(children) => (
|
|
114
|
+
<div title={tooltipText}>
|
|
115
|
+
{children}
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
>
|
|
119
|
+
<button>Action Button</button>
|
|
120
|
+
</ConditionalWrap>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Conditional Form Wrappers
|
|
124
|
+
Wrap form elements conditionally:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
<ConditionalWrap
|
|
128
|
+
condition={isDisabled}
|
|
129
|
+
wrap={(children) => (
|
|
130
|
+
<fieldset disabled>
|
|
131
|
+
{children}
|
|
132
|
+
</fieldset>
|
|
133
|
+
)}
|
|
134
|
+
>
|
|
135
|
+
<input type="text" />
|
|
136
|
+
</ConditionalWrap>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Behavior
|
|
142
|
+
|
|
143
|
+
- When `condition` is `true`, the `wrap` function is called with `children` as argument
|
|
144
|
+
- When `condition` is `false`, `children` are returned unchanged
|
|
145
|
+
- The component is a pure function with no side effects
|
|
146
|
+
- Only accepts a single child element (ReactElement)
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Performance
|
|
151
|
+
|
|
152
|
+
- Very lightweight component with minimal overhead
|
|
153
|
+
- No state or effects, purely functional
|
|
154
|
+
- Wrapper function is only called when condition is true
|
|
155
|
+
- Consider memoizing the wrap function if it's expensive to create
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Migration
|
|
160
|
+
|
|
161
|
+
If migrating from a previous version:
|
|
162
|
+
|
|
163
|
+
```diff
|
|
164
|
+
- import { ConditionalWrap } from 'old-package';
|
|
165
|
+
+ import ConditionalWrap from '@cleartrip/ct-design-conditional-wrap';
|
|
166
|
+
```
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.
|
|
1
|
+
"use strict";function e({condition:e,wrap:t,children:r}){return e?t(r):r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionalWrap=e,exports.default=e;
|
|
2
2
|
//# sourceMappingURL=ct-design-conditional-wrapper.browser.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-conditional-wrapper.browser.cjs.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"ct-design-conditional-wrapper.browser.cjs.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":["ConditionalWrap","condition","wrap","children"],"mappings":"aAEM,SAAUA,GAAgBC,UAC9BA,EAASC,KACTA,EAAIC,SACJA,IAMA,OAAOF,EAAYC,EAAKC,GAAYA,CACtC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function n(
|
|
1
|
+
function n({condition:n,wrap:r,children:t}){return n?r(t):t}export{n as ConditionalWrap,n as default};
|
|
2
2
|
//# sourceMappingURL=ct-design-conditional-wrapper.browser.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-conditional-wrapper.browser.esm.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":["ConditionalWrap","
|
|
1
|
+
{"version":3,"file":"ct-design-conditional-wrapper.browser.esm.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":["ConditionalWrap","condition","wrap","children"],"mappings":"AAEM,SAAUA,GAAgBC,UAC9BA,EAASC,KACTA,EAAIC,SACJA,IAMA,OAAOF,EAAYC,EAAKC,GAAYA,CACtC"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function ConditionalWrap(
|
|
6
|
-
var condition = _a.condition, wrap = _a.wrap, children = _a.children;
|
|
5
|
+
function ConditionalWrap({ condition, wrap, children, }) {
|
|
7
6
|
return condition ? wrap(children) : children;
|
|
8
7
|
}
|
|
9
8
|
|
|
9
|
+
exports.ConditionalWrap = ConditionalWrap;
|
|
10
10
|
exports.default = ConditionalWrap;
|
|
11
11
|
//# sourceMappingURL=ct-design-conditional-wrapper.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-conditional-wrapper.cjs.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"ct-design-conditional-wrapper.cjs.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAEM,SAAU,eAAe,CAAC,EAC9B,SAAS,EACT,IAAI,EACJ,QAAQ,GAKT,EAAA;AACC,IAAA,OAAO,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAC/C;;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
function ConditionalWrap(
|
|
2
|
-
var condition = _a.condition, wrap = _a.wrap, children = _a.children;
|
|
1
|
+
function ConditionalWrap({ condition, wrap, children, }) {
|
|
3
2
|
return condition ? wrap(children) : children;
|
|
4
3
|
}
|
|
5
4
|
|
|
6
|
-
export { ConditionalWrap as default };
|
|
5
|
+
export { ConditionalWrap, ConditionalWrap as default };
|
|
7
6
|
//# sourceMappingURL=ct-design-conditional-wrapper.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-conditional-wrapper.esm.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ct-design-conditional-wrapper.esm.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEM,SAAU,eAAe,CAAC,EAC9B,SAAS,EACT,IAAI,EACJ,QAAQ,GAKT,EAAA;AACC,IAAA,OAAO,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAC/C;;;;"}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystem = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function ConditionalWrap(
|
|
8
|
-
var condition = _a.condition, wrap = _a.wrap, children = _a.children;
|
|
7
|
+
function ConditionalWrap({ condition, wrap, children, }) {
|
|
9
8
|
return condition ? wrap(children) : children;
|
|
10
9
|
}
|
|
11
10
|
|
|
11
|
+
exports.ConditionalWrap = ConditionalWrap;
|
|
12
12
|
exports.default = ConditionalWrap;
|
|
13
13
|
|
|
14
14
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-conditional-wrapper.umd.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ct-design-conditional-wrapper.umd.js","sources":["../packages/components/ConditionalWrap/src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;IAEM,SAAU,eAAe,CAAC,EAC9B,SAAS,EACT,IAAI,EACJ,QAAQ,GAKT,EAAA;IACC,IAAA,OAAO,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAC/C;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
declare function ConditionalWrap({ condition, wrap, children, }: {
|
|
2
|
+
export declare function ConditionalWrap({ condition, wrap, children, }: {
|
|
3
3
|
condition: boolean;
|
|
4
4
|
wrap: (component: typeof children) => ReactElement;
|
|
5
5
|
children: ReactElement;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/components/ConditionalWrap/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/components/ConditionalWrap/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,IAAI,EACJ,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,CAAC,SAAS,EAAE,OAAO,QAAQ,KAAK,YAAY,CAAC;IACnD,QAAQ,EAAE,YAAY,CAAC;CACxB,GAAG,YAAY,CAEf;AAED,eAAe,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleartrip/ct-design-conditional-wrap",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0-SNAPSHOT-native-main.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
-
"main": "dist/ct-design-conditional-wrapper.cjs.js",
|
|
6
|
+
"main": "./dist/ct-design-conditional-wrapper.cjs.js",
|
|
7
7
|
"jsnext:main": "dist/ct-design-conditional-wrapper.esm.js",
|
|
8
8
|
"module": "dist/ct-design-conditional-wrapper.esm.js",
|
|
9
9
|
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/ct-design-conditional-wrapper.esm.js",
|
|
14
|
+
"default": "./dist/ct-design-conditional-wrapper.cjs.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
10
17
|
"browser": {
|
|
11
18
|
"./dist/ct-design-conditional-wrapper.esm.js": "./dist/ct-design-conditional-wrapper.browser.esm.js",
|
|
12
19
|
"./dist/ct-design-conditional-wrapper.cjs.js": "./dist/ct-design-conditional-wrapper.browser.cjs.js"
|
|
13
20
|
},
|
|
14
21
|
"files": [
|
|
15
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
16
24
|
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@cleartrip/ct-design-theme": "4.0.0-SNAPSHOT-native-main.12"
|
|
27
|
+
},
|
|
17
28
|
"peerDependencies": {
|
|
18
29
|
"react": ">=16.8.0",
|
|
19
30
|
"react-dom": ">=16.8.0"
|
|
@@ -26,6 +37,8 @@
|
|
|
26
37
|
"scripts": {
|
|
27
38
|
"watch-package": "rollup -c -w",
|
|
28
39
|
"build-package": "rollup -c",
|
|
29
|
-
"build-package:clean": "rm -rf dist && rollup -c"
|
|
40
|
+
"build-package:clean": "rm -rf dist && rollup -c",
|
|
41
|
+
"publish-package:local": "yalc publish --no-scripts",
|
|
42
|
+
"publish-package:local:registry": "pnpm publish --registry http://localhost:4873 --no-git-checks --access public"
|
|
30
43
|
}
|
|
31
44
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
export function ConditionalWrap({
|
|
4
|
+
condition,
|
|
5
|
+
wrap,
|
|
6
|
+
children,
|
|
7
|
+
}: {
|
|
8
|
+
condition: boolean;
|
|
9
|
+
wrap: (component: typeof children) => ReactElement;
|
|
10
|
+
children: ReactElement;
|
|
11
|
+
}): ReactElement {
|
|
12
|
+
return condition ? wrap(children) : children;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default ConditionalWrap;
|