Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Visibility): add support for being used in Flex.Container #3203

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ showTabs: true
tabs:
- title: Info
key: '/info'
- title: Demos
key: '/demos'
- title: Properties
key: '/properties'
breadcrumb:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,67 @@
import React from 'react'
import ComponentBox from '../../../../../../shared/tags/ComponentBox'
import { P } from '@dnb/eufemia/src'
import { Form, Visibility } from '@dnb/eufemia/src/extensions/forms'
import { Flex, P } from '@dnb/eufemia/src'
import {
Field,
Form,
TestElement,
Visibility,
} from '@dnb/eufemia/src/extensions/forms'

export const BasedOnBooleanTrue = () => {
export const BooleanExample = () => {
return (
<ComponentBox scope={{ Visibility, TestElement }}>
<Form.Handler>
<Flex.Stack>
<Field.Boolean
variant="buttons"
path="/toggleValue"
label="Show content"
value={false}
/>
<Visibility pathTrue="/toggleValue">
<TestElement>Item 1</TestElement>
<TestElement>Item 2</TestElement>
</Visibility>
</Flex.Stack>
</Form.Handler>
</ComponentBox>
)
}

export const InferData = () => {
return (
<ComponentBox scope={{ Visibility }}>
<Visibility visible={true}>This is visible</Visibility>
{() => {
const MyComponent = () => {
const [state, setState] = React.useState(false)
const inferData = React.useCallback(() => state, [state])

return (
<Form.Handler>
<Field.Boolean
path="/toggleValue"
onChange={setState}
label="Check me"
/>
<Visibility inferData={inferData}>
<P>This is visible</P>
</Visibility>
</Form.Handler>
)
}

return <MyComponent />
}}
</ComponentBox>
)
}

export const BasedOnBooleanFalse = () => {
export const BasedOnBooleanTrue = () => {
return (
<ComponentBox scope={{ Visibility }}>
<Visibility visible={{ foo: 'foo' }.foo === 'bar'}>
This is not visible
<Visibility visible={true}>
<P>This is visible</P>
</Visibility>
</ComponentBox>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import * as Examples from './Examples'

## Demos

### Direct properties
### Boolean example

<Examples.BasedOnBooleanTrue />
<Examples.BooleanExample />

### False (not visible)
### Direct properties

<Examples.BasedOnBooleanFalse />
<Examples.BasedOnBooleanTrue />

### Based on DataContext

<Examples.BasedOnContext />

### InferData

<Examples.InferData />
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ function Visibility({
return <>{children}</>
}

Visibility._supportsSpacingProps = true
Visibility._supportsSpacingProps = 'children'
export default Visibility
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ describe('Visibility', () => {
expect(screen.getByText('Child')).toBeInTheDocument()
})

it('should have constant of _supportsSpacingProps="children"', () => {
expect(Visibility._supportsSpacingProps).toBe('children')
})

describe('visibility-prop', () => {
it('renders children when visible is true', () => {
render(<Visibility visible={true}>Child</Visibility>)
Expand Down
Loading