Skip to content

Commit

Permalink
Merge pull request #26 from ahmetarsiv/master
Browse files Browse the repository at this point in the history
Bug fixed Export
  • Loading branch information
ahmetarsiv authored May 29, 2024
2 parents 5627c36 + 6dcfe98 commit bd0d875
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codenteq/interfeys",
"version": "0.5.0",
"version": "0.5.1",
"description": "Codenteq Interfeys Design System",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
70 changes: 3 additions & 67 deletions src/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
import React, { useState, ReactNode, createContext, useContext } from 'react';
import { motion } from 'framer-motion';

interface AccordionProps {
children: ReactNode;
}
import React, { useState, ReactNode, createContext } from 'react';

interface AccordionItemProps {
children: ReactNode;
}

interface AccordionHeaderProps {
children: ReactNode;
className?: string;
}

interface AccordionBodyProps {
children: ReactNode;
className?: string;
}

const AccordionContext = createContext({
isOpen: false,
toggle: () => {},
});

export const AccordionList = ({ children }: AccordionProps) => {
return <div>{children}</div>;
};

export const Accordion = ({ children }: AccordionItemProps) => {
const Accordion = ({ children }: AccordionItemProps) => {
const [isOpen, setIsOpen] = useState(false);

const toggle = () => setIsOpen(!isOpen);
Expand All @@ -42,50 +23,5 @@ export const Accordion = ({ children }: AccordionItemProps) => {
);
};

export const AccordionHeader = ({
children,
className,
}: AccordionHeaderProps) => {
const { isOpen, toggle } = useContext(AccordionContext);
return (
<div className="border-b border-gray-200 dark:border-gray-700">
<motion.button
type="button"
className={`flex items-center justify-between w-full py-5 ${className}`}
onClick={toggle}>
{children}
<svg
className={`w-3 h-3 transform ${isOpen ? 'rotate-180' : ''}`}
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 10 6">
<path
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M9 5L5 1 1 5"
/>
</svg>
</motion.button>
</div>
);
};

export const AccordionBody = ({ children, className }: AccordionBodyProps) => {
const { isOpen } = useContext(AccordionContext);
return (
<motion.div
className={`${className} ${isOpen ? 'block' : 'hidden'}`}
initial={{ height: 0 }}
animate={{ height: isOpen ? 'auto' : 0 }}
transition={{ duration: 0.3 }}>
<div className={`py-5 ${isOpen ? 'block' : 'hidden'}`}>
{children}
</div>
</motion.div>
);
};

export { AccordionContext };
export default Accordion;
25 changes: 25 additions & 0 deletions src/accordion/AccordionBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useContext, ReactNode } from 'react';
import { motion } from 'framer-motion';
import { AccordionContext } from './Accordion';

interface AccordionBodyProps {
children: ReactNode;
className?: string;
}

const AccordionBody = ({ children, className }: AccordionBodyProps) => {
const { isOpen } = useContext(AccordionContext);
return (
<motion.div
className={`${className} ${isOpen ? 'block' : 'hidden'}`}
initial={{ height: 0 }}
animate={{ height: isOpen ? 'auto' : 0 }}
transition={{ duration: 0.3 }}>
<div className={`py-5 ${isOpen ? 'block' : 'hidden'}`}>
{children}
</div>
</motion.div>
);
};

export default AccordionBody;
38 changes: 38 additions & 0 deletions src/accordion/AccordionHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useContext, ReactNode } from 'react';
import { motion } from 'framer-motion';
import { AccordionContext } from './Accordion';

interface AccordionHeaderProps {
children: ReactNode;
className?: string;
}

const AccordionHeader = ({ children, className }: AccordionHeaderProps) => {
const { isOpen, toggle } = useContext(AccordionContext);
return (
<div className="border-b border-gray-200 dark:border-gray-700">
<motion.button
type="button"
className={`flex items-center justify-between w-full py-5 ${className}`}
onClick={toggle}>
{children}
<svg
className={`w-3 h-3 transform ${isOpen ? 'rotate-180' : ''}`}
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 10 6">
<path
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M9 5L5 1 1 5"
/>
</svg>
</motion.button>
</div>
);
};

export default AccordionHeader;
11 changes: 11 additions & 0 deletions src/accordion/AccordionList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { ReactNode } from 'react';

interface AccordionProps {
children: ReactNode;
}

const AccordionList = ({ children }: AccordionProps) => {
return <div>{children}</div>;
};

export default AccordionList;
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ export { default as Drawer } from './drawer/Drawer';
export { default as Dialog } from './dialog/Dialog';
export { default as Popover } from './popover/Popover';
export { default as Accordion } from './accordion/Accordion';
export { default as AccordionBody } from './accordion/AccordionBody';
export { default as AccordionHeader } from './accordion/AccordionHeader';
export { default as AccordionList } from './accordion/AccordionList';
6 changes: 3 additions & 3 deletions stories/Accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import type { Meta } from '@storybook/react';
import {
Accordion,
AccordionBody,
AccordionHeader,
Accordion,
AccordionList,
} from '../src/accordion/Accordion';
import type { Meta } from '@storybook/react';
} from '../src/';

const meta = {
title: 'Components/Accordion',
Expand Down

0 comments on commit bd0d875

Please sign in to comment.