Skip to content

Commit

Permalink
feat: className/hiddenMode add default value.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 17, 2023
1 parent 2d4ad56 commit 1646906
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ export default function App() {
}
```

## props
## \<Only /> props

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

### hiddenMode enum
**`hiddenMode` enum**

| hiddenMode | description |
| ----- | ----- |
Expand Down
2 changes: 1 addition & 1 deletion core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface OnlyWhenProps {
}

export default function OnlyWhen(props: PropsWithChildren<OnlyWhenProps>) {
const { children, when, hiddenMode, className } = props;
const { children, when, hiddenMode = 'null', className = 'w-hidden' } = props;
const singleChild = React.Children.only(children);
const { style, ...restOfChildProps } = singleChild.props;
const extendedProps = { ...restOfChildProps };
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('<Only />', () => {
expect(only.type).toEqual('span');
expect(only.props.id).toEqual('child');
expect(only.props.children).toBeUndefined();
expect(only.props.className).toEqual('test-className');
expect(only.props.className).toEqual('test-className w-hidden');
expect(only.props.style).toEqual({ color: 'green' });
}
});
Expand All @@ -100,7 +100,7 @@ describe('<Only />', () => {
}
});

it('Joining className = undefined', () => {
it('Joining className default value', () => {
const component = TestRenderer.create(
<Only when={false} hiddenMode="css">
<span id="child" style={{ color: 'green' }} />
Expand All @@ -112,7 +112,7 @@ describe('<Only />', () => {
expect(only.type).toEqual('span');
expect(only.props.id).toEqual('child');
expect(only.props.children).toBeUndefined();
expect(only.props.className).toEqual('');
expect(only.props.className).toEqual('w-hidden');
expect(only.props.style).toEqual({ color: 'green' });
}
});
Expand Down

0 comments on commit 1646906

Please sign in to comment.