Skip to content

Commit

Permalink
feat(Forms): add inheritLabel to Value.SummaryList
Browse files Browse the repository at this point in the history
  • Loading branch information
langz committed Sep 26, 2024
1 parent d1b31d8 commit 2609d0d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,21 @@ export function InheritVisibility() {
</ComponentBox>
)
}

export function InheritLabel() {
return (
<ComponentBox>
<Form.Handler>
<Card stack>
<Field.Name.First path="/foo" />
<Field.Name.Last path="/bar" />

<Value.SummaryList inheritVisibility>
<Value.Name.First path="/foo" />
<Value.Name.First path="/bar" />
</Value.SummaryList>
</Card>
</Form.Handler>
</ComponentBox>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ Using [Value.Composition](/uilib/extensions/forms/Value/Composition/) to combine
### Inherit visibility

<Examples.InheritVisibility />

### Inherit label

<Examples.InheritVisibility />
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import Dl, { DlAllProps } from '../../../../elements/Dl'

export type Props = Omit<DlAllProps, 'label'> & {
inheritVisibility?: boolean
inheritLabel?: boolean
}

function SummaryList(props: Props) {
const { className, children, layout, inheritVisibility, ...rest } = props
const {
className,
children,
layout,
inheritVisibility,
inheritLabel,
...rest
} = props
return (
<SummaryListContext.Provider value={{ layout, inheritVisibility }}>
<SummaryListContext.Provider
value={{ layout, inheritVisibility, inheritLabel }}
>
<Dl
className={classnames('dnb-forms-summary-list', className)}
layout={layout}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type SummaryListContextProps = {
layout?: DlProps['layout']
isNested?: boolean
inheritVisibility?: boolean
inheritLabel?: boolean
}

const SummaryListContext = React.createContext<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const SummaryListProperties: PropertiesTableProps = {
type: 'boolean',
status: 'optional',
},
inheritLabel: {
doc: 'Use this property to propagate the `inheritLabel` property to all nested values.',
type: 'boolean',
status: 'optional',
},
children: {
doc: 'Contents.',
type: 'React.Node',
Expand Down
10 changes: 7 additions & 3 deletions packages/dnb-eufemia/src/extensions/forms/hooks/useValueProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default function useValueProps<
value: valueProp,
itemPath,
defaultValue,
inheritLabel,
inheritVisibility: inheritVisibilityProp,
inheritLabel: inheritLabelProp,
transformIn = (value: Value) => value,
toInput = (value: Value) => value,
fromExternal = (value: Value) => value,
Expand All @@ -47,11 +47,15 @@ export default function useValueProps<
transformers,
}) ?? defaultValue

const { inheritVisibility: inheritVisibilitySummaryList } =
useContext(SummaryListContext) || {}
const {
inheritVisibility: inheritVisibilitySummaryList,
inheritLabel: inheritLabelSummaryList,
} = useContext(SummaryListContext) || {}
const inheritVisibility =
inheritVisibilityProp ?? inheritVisibilitySummaryList

const inheritLabel = inheritLabelProp ?? inheritLabelSummaryList

const {
fieldPropsRef,
mountedFieldsRef,
Expand Down

0 comments on commit 2609d0d

Please sign in to comment.