Skip to content

Commit

Permalink
docs(PhoneNumber): remove unsupported props (#2894)
Browse files Browse the repository at this point in the history
This way we can simply list props that are not supported for various
reasons:

```mdx
<DataValueReadwriteProperties
  type="string"
  omit={[
    'layout',
    'label',
    'labelDescription',
    'labelSecondary',
    'emptyValue',
  ]}
/>
```
  • Loading branch information
tujoworker authored Nov 13, 2023
1 parent 0ca9533 commit 4800a8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { OmitTableProperties } from 'dnb-design-system-portal/src/shared/tags/Table'

### Standard data value component props

<OmitTableProperties>

| Property | Type | Description |
| ---------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `className` | `string` | _(optional)_ Outer DOM element class name. |
Expand Down Expand Up @@ -27,3 +31,10 @@
| `onBlurValidator` | `function` | _(optional)_ Custom validator function that will be called when the user leaves the field (blurring a text input, closing a dropdown etc). Can be asynchronous or synchronous. |
| `toInput` | `function` | _(optional)_ Derivate called when the received / active value is sent to the input. Can be used for casting, changing syntax etc. |
| `fromInput` | `function` | _(optional)_ Derivate called when changes is made by the user, to cast or change syntax back to the original (opposite of `toInput`). |

</OmitTableProperties>

export default function Layout({ omit = null, children }) {
globalThis.omitTableProperties = omit
return <>{children}</>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ import DataValueReadwriteProperties from '../../data-value-readwrite-properties.
| `width` | `string` or `false` | _(optional)_ `large` for predefined standard width, `stretch` for fill available width. |
| [Space](/uilib/layout/space/properties) | Various | _(optional)_ Spacing properties like `top` or `bottom` are supported. |

<DataValueReadwriteProperties type="string" />
<DataValueReadwriteProperties
type="string"
omit={[
'layout',
'label',
'labelDescription',
'labelSecondary',
'emptyValue',
]}
/>
25 changes: 25 additions & 0 deletions packages/dnb-design-system-portal/src/shared/tags/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ const StyledTable = styled(TableElement)`
}
`

export function OmitTableProperties({ children, ...rest }) {
const omitProperties = globalThis.omitTableProperties || []

return recursiveMap(children, (child: React.ReactElement) => {
if (child.type === 'tr') {
const firstTd = getFirstChild(child)

if (firstTd.type === 'td') {
const tdContent = getFirstChild(firstTd)
const name = getFirstChild(tdContent)

if (omitProperties.includes(name)) {
return null
}
}
}

return child
})
}

export default function Table({ children }) {
// make sure we get the table children
children =
Expand Down Expand Up @@ -56,6 +77,10 @@ export default function Table({ children }) {
)
}

function getFirstChild(children: ChildrenWithChildren) {
return children.props.children.at(0)
}

function getChildren(children: ChildrenWithChildren) {
return recursiveMap(children.props.children, (child) => child)
}
Expand Down

0 comments on commit 4800a8e

Please sign in to comment.