File tree Expand file tree Collapse file tree 5 files changed +92
-7
lines changed Expand file tree Collapse file tree 5 files changed +92
-7
lines changed Original file line number Diff line number Diff line change 1+ import { Button , Centering , Dropdown } from '@solved-ac/ui-react'
2+ import { Meta , StoryFn } from '@storybook/react'
3+ import React from 'react'
4+
5+ import TooltipStories from './Tooltip.stories'
6+
7+ export default {
8+ title : 'Components/Dropdown' ,
9+ component : Dropdown ,
10+ argTypes : {
11+ ...TooltipStories . argTypes ,
12+ interactive : {
13+ ...( TooltipStories . argTypes ?. interactive || { } ) ,
14+ defaultValue : true ,
15+ } ,
16+ activateOnHover : {
17+ ...( TooltipStories . argTypes ?. activateOnHover || { } ) ,
18+ defaultValue : false ,
19+ } ,
20+ activateOnClick : {
21+ ...( TooltipStories . argTypes ?. activateOnClick || { } ) ,
22+ defaultValue : true ,
23+ } ,
24+ noThemeChange : {
25+ ...( TooltipStories . argTypes ?. noThemeChange || { } ) ,
26+ defaultValue : true ,
27+ } ,
28+ } ,
29+ } as Meta < typeof Dropdown >
30+
31+ const Template : StoryFn < typeof Dropdown > = ( args ) => (
32+ < Centering
33+ style = { {
34+ height : 200 ,
35+ } }
36+ >
37+ < Dropdown { ...args } />
38+ </ Centering >
39+ )
40+
41+ export const Default = Template . bind ( { } )
42+ Default . args = {
43+ children : < Button > Click me!</ Button > ,
44+ title : 'Dropdown' ,
45+ }
Original file line number Diff line number Diff line change @@ -11,11 +11,6 @@ export default {
1111 description : 'The title to display' ,
1212 defaultValue : 'Tooltip' ,
1313 } ,
14- noDefaultStyles : {
15- control : 'boolean' ,
16- description : 'Whether to use the default styles' ,
17- defaultValue : false ,
18- } ,
1914 arrow : {
2015 control : 'boolean' ,
2116 description : 'Whether to show the arrow' ,
@@ -62,6 +57,18 @@ export default {
6257 'Whether to activate the tooltip on mouse click - repeated clicks will toggle the tooltip' ,
6358 defaultValue : false ,
6459 } ,
60+ noDefaultStyles : {
61+ control : 'boolean' ,
62+ description :
63+ 'Whether to use the default styles - this will also disable the theme change.' ,
64+ defaultValue : false ,
65+ } ,
66+ noThemeChange : {
67+ control : 'boolean' ,
68+ description :
69+ 'Whether to prevent the theme from changing - Tooltip is set to use the dark theme by default. This will prevent that.' ,
70+ defaultValue : false ,
71+ } ,
6572 } ,
6673} as Meta < typeof Tooltip >
6774
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import { Tooltip , TooltipProps } from './Tooltip'
3+
4+ export type DropdownProps = TooltipProps
5+
6+ export const Dropdown : React . FC < TooltipProps > = ( props ) => {
7+ const {
8+ interactive = true ,
9+ activateOnHover = false ,
10+ activateOnClick = true ,
11+ noThemeChange = true ,
12+ ...rest
13+ } = props
14+
15+ return (
16+ < Tooltip
17+ interactive = { interactive }
18+ activateOnHover = { activateOnHover }
19+ activateOnClick = { activateOnClick }
20+ noThemeChange = { noThemeChange }
21+ { ...rest }
22+ />
23+ )
24+ }
Original file line number Diff line number Diff line change 99 safePolygon ,
1010 shift ,
1111 useClick ,
12+ useDismiss ,
1213 useFloating ,
1314 useHover ,
1415 useInteractions ,
@@ -71,6 +72,7 @@ export type TooltipProps = {
7172 interactive ?: boolean
7273 activateOnHover ?: boolean
7374 activateOnClick ?: boolean
75+ noThemeChange ?: boolean
7476} & (
7577 | {
7678 noDefaultStyles : false
@@ -128,6 +130,7 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
128130 interactive = false ,
129131 activateOnHover = true ,
130132 activateOnClick = false ,
133+ noThemeChange = false ,
131134 ...cardProps
132135 } = props
133136 const [ isOpen , setIsOpen ] = useState ( false )
@@ -172,9 +175,14 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
172175 useClick ( context , {
173176 enabled : activateOnClick ,
174177 } ) ,
178+ useDismiss ( context , {
179+ enabled : activateOnClick && ! keepOpen ,
180+ } ) ,
175181 ] )
176182
177183 const RenderComponent = noBackground ? motion . div : TooltipContainer
184+ const ThemeProviderComponent =
185+ noThemeChange || noBackground ? React . Fragment : ThemeProvider
178186
179187 const arrowPosition =
180188 renderSide [ placement . split ( '-' ) [ 0 ] as keyof typeof renderSide ]
@@ -185,7 +193,7 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
185193 { children }
186194 </ TooltipWrapper >
187195 < FloatingPortal >
188- < ThemeProvider theme = { theme || solvedThemes . dark } >
196+ < ThemeProviderComponent theme = { theme || solvedThemes . dark } >
189197 < AnimatePresence >
190198 { renderTooltip && (
191199 < React . Fragment >
@@ -216,7 +224,7 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
216224 </ React . Fragment >
217225 ) }
218226 </ AnimatePresence >
219- </ ThemeProvider >
227+ </ ThemeProviderComponent >
220228 </ FloatingPortal >
221229 </ React . Fragment >
222230 )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export * from './Chip'
1010export * from './Collapse'
1111export * from './Container'
1212export * from './Divider'
13+ export * from './Dropdown'
1314export * from './EmptyStatePlaceholder'
1415export * from './Footer'
1516export * from './NavBar'
You can’t perform that action at this time.
0 commit comments