MCPcopy Create free account
hub / github.com/dailydotdev/apps / ButtonComponent

Function ButtonComponent

packages/shared/src/components/buttons/Button.tsx:116–228  ·  view source on GitHub ↗
(
  {
    variant,
    size = ButtonSize.Medium,
    color,
    className,
    icon,
    iconPosition = ButtonIconPosition.Left,
    iconSecondaryOnHover = false,
    loading,
    pressed,
    inactive,
    bold,
    useDefaultCursor,
    disabled,
    children,
    onClick,
    tag: Tag = 'button',
    ...props
  }: ButtonProps<TagName>,
  ref?: Ref<ButtonElementType<TagName>>,
)

Source from the content-addressed store, hash-verified

114};
115
116function ButtonComponent<TagName extends AllowedTags>(
117 {
118 variant,
119 size = ButtonSize.Medium,
120 color,
121 className,
122 icon,
123 iconPosition = ButtonIconPosition.Left,
124 iconSecondaryOnHover = false,
125 loading,
126 pressed,
127 inactive,
128 bold,
129 useDefaultCursor,
130 disabled,
131 children,
132 onClick,
133 tag: Tag = 'button',
134 ...props
135 }: ButtonProps<TagName>,
136 ref?: Ref<ButtonElementType<TagName>>,
137): ReactElement {
138 const childNodes = React.Children.toArray(children);
139 const hasChildren = childNodes.length > 0;
140 const shouldWrapLabel =
141 hasChildren &&
142 childNodes.every(
143 (child) => typeof child === 'string' || typeof child === 'number',
144 );
145 const iconOnly = !!(icon && !hasChildren);
146 const getIconWithSize = useGetIconWithSize(size, iconOnly, iconPosition);
147 const isAnchor = Tag === 'a';
148 const anchorClickProps =
149 isAnchor && onClick
150 ? combinedClicks<HTMLAnchorElement>(
151 onClick as React.MouseEventHandler<HTMLAnchorElement>,
152 )
153 : {};
154 const isOptionOrQuiz =
155 variant === ButtonVariant.Option || variant === ButtonVariant.Quiz;
156 const [isHovering, setIsHovering] = useState(false);
157
158 const ariaDisabled = inactive && !disabled ? true : undefined;
159
160 return (
161 <Tag
162 {...props}
163 {...(isAnchor ? anchorClickProps : { onClick })}
164 aria-busy={loading}
165 aria-pressed={pressed}
166 aria-disabled={ariaDisabled}
167 disabled={disabled}
168 ref={ref}
169 className={classNames(
170 'btn inline-flex select-none flex-row items-center border no-underline shadow-none',
171 useDefaultCursor ? 'cursor-default' : 'cursor-pointer',
172 !isOptionOrQuiz && 'justify-center',
173 variantFontWeight(variant, bold),

Callers

nothing calls this directly

Calls 5

useGetIconWithSizeFunction · 0.90
combinedClicksFunction · 0.90
variantFontWeightFunction · 0.70
sizeClassMapFunction · 0.70
horizontalPaddingClassFunction · 0.70

Tested by

no test coverage detected