-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80f4a3b
commit 45a71d8
Showing
4 changed files
with
91 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Button, Tooltip } from '@equinor/eds-core-react' | ||
import React from 'react' | ||
|
||
type Prefix<T, P extends string> = { | ||
[K in keyof T as `${P}-${string & K}`]: T[K] | ||
} | ||
type PrefixedButton = Prefix< | ||
Omit<React.ComponentProps<typeof Button>, 'aria-label' | 'children'>, | ||
'button' | ||
> | ||
type PrefixedTooltip = Prefix< | ||
Omit<React.ComponentProps<typeof Tooltip>, 'title' | 'children'>, | ||
'tooltip' | ||
> | ||
type TProps = PrefixedButton & | ||
PrefixedTooltip & { title: string; children: React.ReactElement } | ||
|
||
const getProps = (prefix: string, dict: { [k: string]: any }) => { | ||
return Object.fromEntries( | ||
Object.entries(dict) | ||
.filter(([k]) => k.startsWith(prefix)) | ||
.map(([k, v]) => [k.slice(prefix.length), v]) | ||
) | ||
} | ||
|
||
const TooltipButton = (props: TProps) => { | ||
return ( | ||
<Tooltip title={props.title} {...getProps('tooltip-', props)}> | ||
<Button {...getProps('button-', props)} aria-label={props.title}> | ||
{props.children} | ||
</Button> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export default TooltipButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters