-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tooltip component #63
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,123 @@ | ||
import React, { useState } from 'react'; | ||
import { StoryFn, Meta } from '@storybook/react'; | ||
import { Tooltip } from './Tooltip'; | ||
import { Button } from '../Button'; | ||
import { useFloating, useHover, useInteractions } from '@floating-ui/react'; | ||
|
||
export default { | ||
title: 'Components/Tooltip', | ||
component: Tooltip, | ||
args: { | ||
// Shaping the stories through args composition. | ||
arrow: 'none', | ||
}, | ||
parameters: { | ||
design: [ | ||
{ | ||
name: 'light', | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/qUvylGh5ubOWlpqlplVORt/IZ-Design-System---%F0%9F%9A%80-Live?type=design&node-id=790-15542&mode=design&t=CX7vD9P6YQtwJF9w-4', | ||
}, | ||
{ | ||
name: 'dark', | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/qUvylGh5ubOWlpqlplVORt/IZ-Design-System---%F0%9F%9A%80-Live?type=design&node-id=1538-93439&mode=design&t=CX7vD9P6YQtwJF9w-4', | ||
}, | ||
], | ||
}, | ||
} as Meta<typeof Tooltip>; | ||
|
||
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Template: StoryFn<typeof Tooltip> = (args) => { | ||
return <Tooltip {...args}>Example tooltip text</Tooltip>; | ||
}; | ||
|
||
const LongTextTemplate: StoryFn<typeof Tooltip> = (args) => { | ||
return ( | ||
<Tooltip {...args}> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus | ||
scelerisque non lacus vitae tempus. Nullam at vehicula erat. Aliquam erat | ||
volutpat. Pellentesque et fringilla purus, ac blandit odio. Ut volutpat, | ||
mauris sed luctus hendrerit, dui nunc sodales erat, non volutpat nisi | ||
lorem eu dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
Vivamus scelerisque non lacus vitae tempus. Nullam at vehicula erat. | ||
Aliquam erat volutpat. Pellentesque et fringilla purus, ac blandit odio. | ||
Ut volutpat, mauris sed luctus hendrerit, dui nunc sodales erat, non | ||
volutpat nisi lorem eu dolor. | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
const FloatingTemplate: StoryFn<typeof Tooltip> = (args) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const { refs, floatingStyles, context } = useFloating({ | ||
open: isOpen, | ||
onOpenChange: setIsOpen, | ||
}); | ||
|
||
const hover = useHover(context); | ||
|
||
const { getReferenceProps, getFloatingProps } = useInteractions([hover]); | ||
|
||
return ( | ||
<div style={{ height: '120px' }}> | ||
<div | ||
style={{ display: 'inline-block' }} | ||
ref={refs.setReference} | ||
{...getReferenceProps()} | ||
> | ||
<Button label='Hover over this button to show a tooltip' /> | ||
</div> | ||
{isOpen && ( | ||
<div | ||
ref={refs.setFloating} | ||
style={floatingStyles} | ||
{...getFloatingProps()} | ||
> | ||
<Tooltip arrow='top'>Floating tooltip for the button</Tooltip> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* Default (no arrows) | ||
*/ | ||
export const Default = Template.bind({}); | ||
|
||
/** | ||
* Floating tooltip example | ||
*/ | ||
export const FloatingTooltip = FloatingTemplate.bind({}); | ||
|
||
/** | ||
* Arrow up | ||
*/ | ||
export const ArrowUp = Template.bind({}); | ||
ArrowUp.args = { arrow: 'top' }; | ||
|
||
/** | ||
* Arrow down | ||
*/ | ||
export const ArrowDown = Template.bind({}); | ||
ArrowDown.args = { arrow: 'bottom' }; | ||
|
||
/** | ||
* Arrow left | ||
*/ | ||
export const ArrowLeft = Template.bind({}); | ||
ArrowLeft.args = { arrow: 'left' }; | ||
|
||
/** | ||
* Arrow right | ||
*/ | ||
export const ArrowRight = Template.bind({}); | ||
ArrowRight.args = { arrow: 'right' }; | ||
|
||
/** | ||
* Very long text, arrow right | ||
*/ | ||
export const LongText = LongTextTemplate.bind({}); | ||
LongText.args = { arrow: 'right' }; |
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,17 @@ | ||
import React from 'react'; | ||
import { Popup, PopupProps } from '../Popup'; | ||
|
||
/** | ||
* Tooltip component properties | ||
* Extends PopupProps | ||
*/ | ||
export interface TooltipProps extends PopupProps {} | ||
|
||
/** | ||
* Tooltip component | ||
* @param props Tooltip props | ||
* @returns Tooltip component | ||
*/ | ||
export const Tooltip = ({ arrow, children }: TooltipProps) => { | ||
return <Popup arrow={arrow}>{children}</Popup>; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tämä osuus pitäs olla itseasiassa tooltip-komponentin sisällä. Eli tooltipin pitäs itsessään osata kellua. Muuten tää näyttää hyvältä 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rajaus meni vähän väärin mutta tuo floating UI osuus Tooltip-komponentin sisälle siis