Skip to content

Commit

Permalink
docs(Contribution): small types enhancements
Browse files Browse the repository at this point in the history
Following up this comment: #1636 (comment)
  • Loading branch information
tujoworker committed Oct 14, 2022
1 parent d335a14 commit ed9bab5
Showing 1 changed file with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ If you are new to the repository, first check out [what I should know before get
- [SCSS Theming](#scss-theming)
- [SCSS utilities and properties](#scss-utilities-and-properties)
- [Create a local build](#create-a-local-build)
- [Additional support](#additional-support)
- [Additional component support](#additional-component-support)
- [Locale support](#locale-support)
- [Provider support](#provider-support)
- [FormRow support with `includeValidProps`](#formrow-support-with-includevalidprops)
- [Spacing support](#spacing-support)
- [Skeleton support](#skeleton-support)
- [TypeScript types](#typescript-types)
- [Write documentation](#write-documentation)
- [4. Make and run tests](#4-make-and-run-tests)
- [Running tests locally](#running-tests-locally)
Expand Down Expand Up @@ -118,7 +120,7 @@ $ yarn build

You find the output in the `./packages/dnb-eufemia/build` folder.

### Additional support
### Additional component support

#### Locale support

Expand All @@ -140,11 +142,20 @@ And use it as so:
import { Context } from '../../shared'
import { extendPropsWithContext } from '../../shared/component-helper'

import type { LocaleProps } from '../../shared/types'

export type ComponentProps = {
myParam?: string
}
export type ComponentAllProps = ComponentProps &
LocaleProps &
React.HTMLProps<HTMLElement>

const defaultProps = {
myParam: 'value',
}

function MyComponent(props: Types) {
function MyComponent(props: ComponentAllProps) {
const context = React.useContext(Context)

const { myString } = extendPropsWithContext(
Expand All @@ -166,11 +177,18 @@ The function `getTranslation` will along with the properties support both `local
import { Context } from '../../shared'
import { extendPropsWithContext } from '../../shared/component-helper'

export type ComponentProps = {
myParam?: string
}
export type ComponentAllProps = ComponentProps &
LocaleProps &
React.HTMLProps<HTMLElement>

const defaultProps = {
myParam: 'value',
}

function MyComponent(props: Types) {
function MyComponent(props: ComponentAllProps) {
const context = React.useContext(Context)

const { myParam, ...rest } = extendPropsWithContext(
Expand Down Expand Up @@ -226,20 +244,19 @@ import {
spacingPropTypes, // In case you need them as PropTypes
createSpacingClasses,
} from '../space/SpacingHelper'
import {
SpaceProps, // TypeScript type
createSpacingClasses,
} from '../space/Space'

interface MyComponentProps extends SpaceProps {
import type { SpacingProps } from '../../shared/types'

export type ComponentProps = {
myParam?: string
}
export type ComponentAllProps = ComponentProps & SpacingProps

const defaultProps = {
myParam: 'value',
}

function MyComponent(props: MyComponentProps) {
function MyComponent(props: ComponentAllProps) {
const context = React.useContext(Context)

const { myParam, className, ...rest } = extendPropsWithContext(
Expand Down Expand Up @@ -274,11 +291,21 @@ import {
createSkeletonClass,
} from '../skeleton/SkeletonHelper'

const defaultProps = {
skeleton: null,
import type { SkeletonShow } from '../skeleton/Skeleton'

export type ComponentProps = {
/**
* Skeleton should be applied when loading content
* Default: null
*/
skeleton?: SkeletonShow
}
export type ComponentAllProps = ComponentProps &
React.HTMLProps<HTMLElement>

function MyComponent(props: Types) {
const defaultProps = {}

function MyComponent(props: ComponentAllProps) {
const context = React.useContext(Context)

const { skeleton, className, ...rest } = extendPropsWithContext(
Expand All @@ -303,6 +330,21 @@ function MyComponent(props: Types) {
}
```

#### TypeScript types

```tsx
import React from 'react'
import type { SpacingProps } from '../../shared/types'
import type { ComponentProps } from './my-component/types'

export type * from './new-component/types'

export type ComponentAllProps = ComponentProps &
React.HTMLProps<HTMLElement>

function MyComponent(props: ComponentAllProps) {}
```

### Write documentation

All components have their own directory inside:
Expand Down

0 comments on commit ed9bab5

Please sign in to comment.