Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, {useState} from 'react';
import React, {useState} from 'react'
import AccordionRoot from './shards/AccordionRoot';
import AccordionItem from './shards/AccordionItem';
import AccordionHeader from './shards/AccordionHeader';
import AccordionTrigger from './shards/AccordionTrigger';
import AccordionContent from './shards/AccordionContent';

const Accordion = ({items}) => {
const [activeIndex, setActiveIndex] = useState(null);
interface AccordionProps {
items: {content: any}[];
}

const handleClick = (index) => {
setActiveIndex(activeIndex === index ? null : index);
const Accordion = ({items} : AccordionProps) => {
const [activeIndex, setActiveIndex] = useState<number>(-1);
const handleClick = (index: number) => {
setActiveIndex(activeIndex === index ? -1 : index);
};

return (
Expand Down
8 changes: 3 additions & 5 deletions src/components/ui/Accordion/shards/AccordionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {customClassSwitcher} from '~/core';
type AccordionContentProps = {
children: React.ReactNode;
index: number,
activeIndex: number,
customRootClass:string
activeIndex: number,
customRootClass? :string
};

const AccordionContent: React.FC<AccordionContentProps> = ({children, index, activeIndex, customRootClass=''}) => {
const AccordionContent: React.FC<AccordionContentProps> = ({children, index, activeIndex, customRootClass}: AccordionContentProps) => {
const rootClass = customClassSwitcher(customRootClass, 'Accordion');
return (
<span className={`${rootClass}-content`}>
Expand All @@ -21,10 +21,8 @@ const AccordionContent: React.FC<AccordionContentProps> = ({children, index, act
>
{children}
</div>

</span>
);
};

export default AccordionContent;

6 changes: 3 additions & 3 deletions src/components/ui/Accordion/shards/AccordionRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
// @ts-ignore
import {customClassSwitcher} from '~/core';

interface AccordionRootProps {
export interface AccordionRootProps {
children: React.ReactNode;
customRootClass?: string;
}

const AccordionRoot: React.FC<AccordionRootProps> = ({children, customRootClass=''}) => {
const AccordionRoot= ({children, customRootClass}: AccordionRootProps) => {
const rootClass = customClassSwitcher(customRootClass, 'Accordion');
return (
<span className={`${rootClass}-root`}>
Expand All @@ -16,4 +16,4 @@ const AccordionRoot: React.FC<AccordionRootProps> = ({children, customRootClass=
);
};

export default AccordionRoot;
export default AccordionRoot;
6 changes: 3 additions & 3 deletions src/components/ui/Accordion/shards/AccordionTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {customClassSwitcher} from '~/core';

type AccordionTriggerProps = {
children: React.ReactNode;
customRootClass:string,
customRootClass?: string,
index: number,
activeIndex: number,
activeIndex: number,
handleClick: (index: number) => void
};

const AccordionTrigger: React.FC<AccordionTriggerProps> = ({children, handleClick, index, activeIndex, customRootClass=''}) => {
const AccordionTrigger: React.FC<AccordionTriggerProps> = ({children, handleClick, index, activeIndex, customRootClass}) => {
const rootClass = customClassSwitcher(customRootClass, 'Accordion');
return (
<span className={`${rootClass}-trigger`}>
Expand Down
21 changes: 9 additions & 12 deletions src/components/ui/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import AvatarRoot from './shards/AvatarRoot';
import AvatarImage from './shards/AvatarImage';
import AvatarFallback from './shards/AvatarFallback';

export interface AvatarProps {
children?: React.ReactNode;
customRootClass?: string;
fallback?: string;
className?: string;
src?: string;
alt?: string;
Root?: React.FC<AvatarRootProps>;
Image?: React.FC<AvatarImageProps>;
Fallback?: React.FC<AvatarFallbackProps>;
interface AvatarProps {
children?: React.ReactNode,
customRootClass?: string,
fallback?: string,
className?: string,
src?: string,
alt?: string,
props?: Record<string, any>[]
}


const Avatar: React.FC<AvatarProps> = ({children, customRootClass = '', fallback='', className = '', src='', alt, ...props}) => {
const Avatar = ({children, customRootClass , fallback, className , src, alt, ...props}: AvatarProps) => {
return (
<AvatarRoot customRootClass={customRootClass}>
<AvatarImage
Expand Down
9 changes: 4 additions & 5 deletions src/components/ui/Avatar/shards/AvatarFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';
// @ts-ignore
import {customClassSwitcher} from '~/core';

export type AvatarFallbackProps = {
fallback: string,
customRootClass: string,
type AvatarFallbackProps = {
fallback?: string,
customRootClass?: string,
};

const AvatarFallback: React.FC<AvatarFallbackProps> = ({fallback='', customRootClass='', ...props}) => {
const AvatarFallback = ({fallback, customRootClass, ...props}: AvatarFallbackProps) => {
const rootClass = customClassSwitcher(customRootClass, 'Avatar');
return (
<span className={`${rootClass}-fallback`} {...props} >
Expand Down
15 changes: 8 additions & 7 deletions src/components/ui/Avatar/shards/AvatarImage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, {useEffect, useState} from 'react';
// @ts-ignore
import {customClassSwitcher} from '~/core';

export type AvatarImageProps = {
src: string;
alt: string;
className: string;
customRootClass: string;
type AvatarImageProps = {
src?: string;
alt?: string;
className?: string;
customRootClass?: string;
props?: Record<string, any>[]
};

const AvatarImage: React.FC<AvatarImageProps> = ({src='', alt='', customRootClass='', className='', ...props}) => {
const AvatarImage = ({src, alt, customRootClass, className, ...props}: AvatarImageProps) => {
const rootClass = customClassSwitcher(customRootClass, 'Avatar');

const [isBrokenImage, setIsBrokenImage] = useState(false);
Expand All @@ -29,6 +29,7 @@ const AvatarImage: React.FC<AvatarImageProps> = ({src='', alt='', customRootClas
console.log('not rendering');
return <></>;
}

console.log(Boolean(src), src);

return (
Expand Down
7 changes: 3 additions & 4 deletions src/components/ui/Avatar/shards/AvatarRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';
// @ts-ignore
import {customClassSwitcher} from '~/core';

export type AvatarRootProps = {
type AvatarRootProps = {
children: React.ReactNode;
customRootClass:string
customRootClass?: string
};

const Root: React.FC<AvatarRootProps> = ({children, customRootClass=''}) => {
const Root = ({children, customRootClass}: AvatarRootProps) => {
const rootClass = customClassSwitcher(customRootClass, 'Avatar');
return (
<span className={`${rootClass}-root`}>
Expand Down
20 changes: 0 additions & 20 deletions src/components/ui/Badge/Badge.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/components/ui/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';
import React from 'react';
import {customClassSwitcher} from '~/core'

const COMPONENT_NAME = 'Badge';

interface BadgeProps {
Copy link
Collaborator

Choose a reason for hiding this comment

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

some of these dont have exports, will that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should discuss on whether or not we want to export all interfaces.

i wasnt sure if there were any potential drawbacks from exposing all interfaces for users (alot may be redundant/confusing), but in terms of rad-ui development, it would make things easier, yes.

children?: React.ReactNode,
customRootClass?: string,
className?: string,
color?: string,
props?: Record<string, any>[],
}


const Badge = ({children, customRootClass, className, color, ...props}: BadgeProps) => {
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME)

return <span className={`${rootClass} ${className}`} data-accent-color={color ?? undefined} {...props}>
{children}
</span>;
};

Badge.displayName = COMPONENT_NAME;

export default Badge;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import React from 'react';
import {customClassSwitcher} from '~/core';

const COMPONENT_NAME = 'BlockQuote';
const BlockQuote = ({children, customRootClass = '', className = '', ...props}) => {

interface BlockQuoteProps {
children: React.ReactNode;
customRootClass?: string;
className?: string;
props: Record<string, any>[]
}
const BlockQuote = ({children, customRootClass, className, ...props}: BlockQuoteProps) => {
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);

return <blockquote className={`${rootClass} ${className}`} {...props}>{children}</blockquote>;
Expand Down
22 changes: 0 additions & 22 deletions src/components/ui/Button/Button.js

This file was deleted.

31 changes: 31 additions & 0 deletions src/components/ui/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';
import React, { RefObject, useRef } from 'react';
// make the color prop default accent color

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
children?: React.ReactNode;
color?: string;
className?: string;
variant: 'solid' | "outline" | "soft" | "ghost";
props?: Record<any, any>[]
buttonRef: RefObject<HTMLButtonElement>
}

const Button = ({children, type='button', color = "", className='', variant='solid', buttonRef, ...props }: ButtonProps) => {
const refButton = useRef<HTMLButtonElement>()
// apply data attribute for accent color
// apply attribute only if color is present

return (
<button
type="button"
ref={buttonRef}
className={`rad-ui-button button-${variant} ${className}`} data-accent-color={color ?? undefined}
{...props}
>
{children}
</button>
);
};

export default Button;