Skip to content

Commit 1646906

Browse files
committed
feat: className/hiddenMode add default value.
1 parent 2d4ad56 commit 1646906

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

core/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ export default function App() {
125125
}
126126
```
127127

128-
## props
128+
## \<Only /> props
129129

130130
| prop name | type | default | isRequired | description |
131131
| ----- | ----- | ----- | ----- | ----- |
132132
| children | react element | `null` | `true` | A single child element |
133133
| when | bool | `false` | `true` | When true, children will rendered as is |
134134
| hiddenMode | string | `null` | `false` | Determines how children should be hidden |
135-
| className | string | `r-o_hidden` | `false` | This is working in combination with `hiddenMode={"css"}` |
135+
| className | string | `w-hidden` | `false` | This is working in combination with `hiddenMode={"css"}` |
136136

137-
### hiddenMode enum
137+
**`hiddenMode` enum**
138138

139139
| hiddenMode | description |
140140
| ----- | ----- |

core/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface OnlyWhenProps {
2121
}
2222

2323
export default function OnlyWhen(props: PropsWithChildren<OnlyWhenProps>) {
24-
const { children, when, hiddenMode, className } = props;
24+
const { children, when, hiddenMode = 'null', className = 'w-hidden' } = props;
2525
const singleChild = React.Children.only(children);
2626
const { style, ...restOfChildProps } = singleChild.props;
2727
const extendedProps = { ...restOfChildProps };

test/index.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('<Only />', () => {
7777
expect(only.type).toEqual('span');
7878
expect(only.props.id).toEqual('child');
7979
expect(only.props.children).toBeUndefined();
80-
expect(only.props.className).toEqual('test-className');
80+
expect(only.props.className).toEqual('test-className w-hidden');
8181
expect(only.props.style).toEqual({ color: 'green' });
8282
}
8383
});
@@ -100,7 +100,7 @@ describe('<Only />', () => {
100100
}
101101
});
102102

103-
it('Joining className = undefined', () => {
103+
it('Joining className default value', () => {
104104
const component = TestRenderer.create(
105105
<Only when={false} hiddenMode="css">
106106
<span id="child" style={{ color: 'green' }} />
@@ -112,7 +112,7 @@ describe('<Only />', () => {
112112
expect(only.type).toEqual('span');
113113
expect(only.props.id).toEqual('child');
114114
expect(only.props.children).toBeUndefined();
115-
expect(only.props.className).toEqual('');
115+
expect(only.props.className).toEqual('w-hidden');
116116
expect(only.props.style).toEqual({ color: 'green' });
117117
}
118118
});

0 commit comments

Comments
 (0)