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

Better Debug for Storybook + Popper API Improvements #155

Merged
merged 3 commits into from
Dec 31, 2023
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
22 changes: 15 additions & 7 deletions src/components/tools/Popper/Popper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useState, useRef} from 'react';
import {customClassSwitcher} from '~/core';

import {useFloating, useInteractions, useHover, FloatingArrow, arrow, offset, flip, autoUpdate, autoPlacement, useRole, useDismiss} from '@floating-ui/react';
import {useFloating, useInteractions, useHover, FloatingArrow, arrow, offset, flip, autoPlacement, hide, shift, autoUpdate, useRole, useDismiss} from '@floating-ui/react';

// TODO : Use Floating Portal?
// TODO : Collisions dont seem to be working as expected, need to investigate
Expand Down Expand Up @@ -36,7 +36,7 @@ const Popper = ({

const {refs, floatingStyles, context} = useFloating({
placement: placement,
whileElementsMounted: autoUpdate,
whileElementsMounted: autoUpdate, // this makes sure the popup is attached to the reference on scrolling etc
open: isOpen,
// strategy: 'fixed',
middleware: [
Expand All @@ -45,10 +45,18 @@ const Popper = ({
}),
offset(ARROW_HEIGHT + GAP),
flip({
mainAxis: false,
fallbackPlacements: ['right', 'bottom'],
mainAxis: true,
fallbackStrategy: 'initialPlacement',
},
),
shift({
crossAxis: false,
}),
hide({
strategy: 'referenceHidden', // 'referenceHidden' by default
}),


],
onOpenChange: setIsOpen,
});
Expand All @@ -66,9 +74,9 @@ const Popper = ({
dismiss,
]);

return <>
return <span>
<span
className={`${rootClass}-reference-element ${className}`} ref={refs.setReference} {...getReferenceProps(
className={`rad-ui-popper ${rootClass}-reference-element ${className}`} ref={refs.setReference} {...getReferenceProps(
{
onClick: () => {
console.log('click');
Expand All @@ -78,7 +86,7 @@ const Popper = ({
{isOpen && <div className={`${rootClass}-floating-element`} ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()} >
{showArrow && <FloatingArrow className={`rad-ui-arrow ${rootClass}-arrow`} ref={arrowRef} context={context} />}
{pop}</div>}
</>;
</span>;
};

export default Popper;
34 changes: 34 additions & 0 deletions src/components/tools/ScrollPlayground/ScrollPlayground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, {useState} from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for storybook ya?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct 👍



import Button from '~/components/ui/Button/Button';

const ScrollPlayground = ({children}) => {
const [scrollable, setScrollable] = useState(false);

const handleScrollableChange = (e) => {
setScrollable((scrollable) => !scrollable);

setTimeout(() => {
const elem = document.getElementById('middle');
if (elem) {
elem.scrollIntoView();
}
}, 100);
};

const SCROLL_BOUNDING_BOX = 200;

return <div className='block bg-plum-200 relative p-2 overflow-auto' style={{height: '300px', width: '300px'}}>
<Button onClick={handleScrollableChange}>{scrollable?'Disable':'Enable Scrollable'}</Button>
<div className='mt-10' style={scrollable?{height: SCROLL_BOUNDING_BOX*4, width: SCROLL_BOUNDING_BOX*4}:{}}>
<div style={scrollable?{marginTop: SCROLL_BOUNDING_BOX*2, paddingLeft: SCROLL_BOUNDING_BOX*2}:{}}>
<span id="middle">
{children}
</span>
</div>
</div>
</div>;
};

export default ScrollPlayground;
4 changes: 2 additions & 2 deletions src/components/ui/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const Dropdown = ({list=[], selected}) => {
})}
</ul>;
};
return <div>
<Popper open={true} placement="bottom-start" popperName="dropdown" pop={<PopElem/>}>
return <div className='relative'>
<Popper open={false} placement="bottom-start" popperName="dropdown" pop={<PopElem/>}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was the previous open flag a mistake? i havent looked at dropdown component yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropdown is still a test component - its not part of the library yet :D

<span>Dropdown</span>
</Popper>
</div>;
Expand Down
12 changes: 10 additions & 2 deletions src/components/ui/Dropdown/Dropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ export default {

<Dropdown
onSelect={() => {}} label={'Bello'} list={[
{value: 'hello', label: 'hello'},
]}>Hello</Dropdown>
{value: `hello Hello this is a dropdown. Hello this is a dropdown.
Hello this is a dropdown. Hello`, label: 'hello'},
]}>
<div>
Hello this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a
dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello
this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a
dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello this is a dropdown. Hello
</div>
</Dropdown>

<div style={{marginTop: '200px'}}>
<Heading className="text-gray-1000"> Dropdown End</Heading>
Expand Down
12 changes: 5 additions & 7 deletions src/components/ui/Tooltip/Tooltip.stories.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@

import {Tooltip, Heading} from '~/';
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';
import ScrollPlayground from '~/components/tools/ScrollPlayground/ScrollPlayground';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
title: 'UI/Input/Tooltip',
component: Tooltip,
render: (args) => <SandboxEditor>
<div className=' bg-gray-400 p-4' >
<div className='block'>
<Heading className="text-gray-1000 mb-4">Tooltip</Heading>
<Tooltip className="text-gray-1000" label="This is a tooltip">
<ScrollPlayground>
<Tooltip className="text-gray-1000" label="This is a tooltip">
Hello, hover me!
</Tooltip>
</div>
</div>
</Tooltip>
</ScrollPlayground>
</SandboxEditor>,
};

Expand Down
4 changes: 4 additions & 0 deletions styles/themes/default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,8 @@ button:active, button:focus, input:active, input:focus, textarea:active, textare
padding: 4px 8px;


}

.rad-ui-popper{
// max-width: calc(100vw - 10px);
}
Loading