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

chore(Housekeeping): rewrite to TypeScript #1565

Merged
merged 3 commits into from
Sep 19, 2022
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
7 changes: 4 additions & 3 deletions packages/dnb-eufemia/src/components/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createSkeletonClass } from '../skeleton/SkeletonHelper'
import Context from '../../shared/Context'
import { ISpacingProps } from '../../shared/interfaces'
import { SkeletonShow } from '../skeleton/Skeleton'
import { extendPropsWithContext } from '../../shared/component-helper'
import { usePropsWithContext } from '../../shared/component-helper'
import { warn } from '../../shared/component-helper'

export interface BadgeProps {
Expand Down Expand Up @@ -78,9 +78,10 @@ export const defaultProps = {
function Badge(localProps: BadgeAndISpacingProps) {
// Every component should have a context
const context = React.useContext(Context)

// Extract additional props from global context
const { children, ...props } = extendPropsWithContext(
{ ...defaultProps, ...localProps },
const { children, ...props } = usePropsWithContext(
localProps,
defaultProps,
context?.Badge
)
Expand Down
13 changes: 6 additions & 7 deletions packages/dnb-eufemia/src/components/button/Button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ export type ButtonOnClick = string | ((...args: any[]) => any);
/**
* NB: Do not change the docs (comments) in here. The docs are updated during build time by "generateTypes.js" and "fetchPropertiesFromDocs.js".
*/
export interface ButtonProps
extends Omit<
React.HTMLProps<HTMLElement>,
'disabled' | 'size' | 'title' | 'wrap'
>,
Partial<DataAttributeTypes> {
export type ButtonProps = {
/**
* The content of the button can be a string or a React Element.
*/
Expand Down Expand Up @@ -230,7 +225,11 @@ export interface ButtonProps
* Will be called on a click event. Returns an object with the native event: `{ event }`.
*/
on_click?: ButtonOnClick;
}
} & Partial<
DataAttributeTypes &
Partial<React.HTMLAttributes<HTMLButtonElement | HTMLAnchorElement>>
>;

export default class Button extends React.Component<ButtonProps, any> {
render(): JSX.Element;
}
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,8 @@ exports[`Dialog component snapshot should match component snapshot 1`] = `
onKeyDown={[Function]}
onTouchStart={[Function]}
>
<ForwardRef(ScrollViewRef)>
<ForwardRef>
<ScrollView
class={null}
className={null}
innerRef={
Object {
"current": <div
Expand Down Expand Up @@ -1199,7 +1197,7 @@ exports[`Dialog component snapshot should match component snapshot 1`] = `
</div>
</div>
</ScrollView>
</ForwardRef(ScrollViewRef)>
</ForwardRef>
</div>
</DialogContent>
</div>
Expand Down
4 changes: 1 addition & 3 deletions packages/dnb-eufemia/src/components/drawer/DrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function DrawerContent({
containerPlacement = 'right',
preventCoreStyle = false,
className = null,
class: _className = null,
spacing = true,
fullscreen = 'auto',
noAnimation = false,
Expand Down Expand Up @@ -61,8 +60,7 @@ export default function DrawerContent({
isTrue(noAnimationOnMobile) && `dnb-drawer--no-animation-on-mobile`,

`dnb-drawer--${containerPlacement || 'right'}`,
className,
_className
className
),
style: (minWidth || maxWidth) && { minWidth, maxWidth },
onClick: context?.preventClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ exports[`Drawer component snapshot should match component snapshot 1`] = `
noAnimation={true}
spacing={true}
>
<ForwardRef(ScrollViewRef)
<ForwardRef
0={
Object {
"displayName": "Drawer",
Expand All @@ -834,7 +834,6 @@ exports[`Drawer component snapshot should match component snapshot 1`] = `
"props": Object {},
}
}
class={null}
className="dnb-drawer dnb-drawer--right dnb-drawer--auto-fullscreen dnb-core-style dnb-drawer--spacing dnb-drawer__align--left dnb-drawer--no-animation"
innerRef={
Object {
Expand Down Expand Up @@ -1214,7 +1213,7 @@ exports[`Drawer component snapshot should match component snapshot 1`] = `
</div>
</div>
</ScrollView>
</ForwardRef(ScrollViewRef)>
</ForwardRef>
</DrawerContent>
</div>
<span
Expand Down
85 changes: 0 additions & 85 deletions packages/dnb-eufemia/src/components/help-button/HelpButton.js

This file was deleted.

62 changes: 62 additions & 0 deletions packages/dnb-eufemia/src/components/help-button/HelpButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Web HelpButton Component
*
*/

import React from 'react'
import Context from '../../shared/Context'
import Modal from '../modal/Modal'
import HelpButtonInstance from './HelpButtonInstance'
import { ButtonProps } from '../button/Button'
import { ModalProps } from '../modal/types'
import { usePropsWithContext } from '../../shared/hooks'

const defaultProps = {
variant: 'secondary',
icon_position: 'left',
}

export type HelpButtonProps = {
modal_content?: React.ReactNode
modal_props?: ModalProps
} & ButtonProps

export default function HelpButton(localProps: HelpButtonProps) {
const getContent = (props: HelpButtonProps) => {
if (props.modal_content) {
return props.modal_content
}
return typeof props.children === 'function'
? props.children(props)
: props.children
}

const context = React.useContext(Context)
const props = usePropsWithContext(localProps, defaultProps)
const content = getContent(props)

const {
modal_content, // eslint-disable-line
children, // eslint-disable-line
modal_props,
...params
} = props

if (params.icon === null) {
params.icon = 'question'
}

if (content) {
if (!params.title) {
params.title = context.getTranslation(props).HelpButton.title
}

return (
<Modal trigger_attributes={params} {...modal_props}>
{content}
</Modal>
)
}

return <HelpButtonInstance {...params} />
}
116 changes: 0 additions & 116 deletions packages/dnb-eufemia/src/components/help-button/HelpButtonInstance.js

This file was deleted.

Loading