Skip to content

Commit

Permalink
New sparkle comp (#1297)
Browse files Browse the repository at this point in the history
* Adding all necessary for Button Menu

* Adding Select type to Dropdown menu

---------

Co-authored-by: édouard wautier <[email protected]>
  • Loading branch information
Duncid and édouard wautier authored Sep 7, 2023
1 parent 57e0182 commit 8878dd0
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 52 deletions.
42 changes: 29 additions & 13 deletions sparkle/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { ComponentType, MouseEvent } from "react";

import { ChevronDown, ChevronUpDown } from "@sparkle/icons/solid";
import { classNames } from "@sparkle/lib/utils";

import { Icon, IconProps } from "./Icon";
import { Tooltip, TooltipProps } from "./Tooltip";

export type ButtonProps = {
type?:
variant?:
| "primary"
| "primaryWarning"
| "secondary"
| "secondaryWarning"
| "tertiary";
type?: "button" | "menu" | "select";
size?: "xs" | "sm" | "md";
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
disabled?: boolean;
Expand All @@ -34,7 +36,7 @@ const containerClasses = {
md: "s-px-1",
};

const typeClasses = {
const variantClasses = {
primary: {
base: "s-text-white s-bg-action-500 s-border-action-600",
hover: "hover:s-bg-action-400 hover:s-border-action-500",
Expand Down Expand Up @@ -97,8 +99,7 @@ const typeClasses = {
},
tertiary: {
base: "s-text-element-800 s-border-structure-200 s-bg-structure-0",
hover:
"hover:s-text-element-700 hover:s-bg-action-50 hover:s-border-action-200",
hover: "hover:s-bg-action-50 hover:s-border-action-200",
active: "active:s-bg-action-100 active:s-border-action-500",
disabled: "s-text-element-500 s-border-structure-200 s-bg-structure-0",
dark: {
Expand All @@ -117,7 +118,8 @@ const transitionClasses =
"s-transition-all s-ease-out s-duration-400 hover:s-scale-100 hover:s-drop-shadow-md active:s-scale-95 active:s-drop-shadow-none s-cursor-pointer";

export function Button({
type = "primary",
variant = "primary",
type = "button",
size = "sm",
onClick,
disabled = false,
Expand All @@ -131,14 +133,14 @@ export function Button({
"s-inline-flex s-items-center s-border s-scale-95 s-box-border s-rounded-full s-whitespace-nowrap",
sizeClasses[size],
!disabled ? transitionClasses : "",
!disabled ? typeClasses[type]?.base : "",
!disabled ? typeClasses[type]?.hover : "",
!disabled ? typeClasses[type]?.active : "",
disabled ? typeClasses[type]?.disabled : "",
typeClasses[type]?.dark?.base,
typeClasses[type]?.dark?.hover,
typeClasses[type]?.dark?.active,
typeClasses[type]?.dark.disabled,
!disabled ? variantClasses[variant]?.base : "",
!disabled ? variantClasses[variant]?.hover : "",
!disabled ? variantClasses[variant]?.active : "",
disabled ? variantClasses[variant]?.disabled : "",
variantClasses[variant]?.dark?.base,
variantClasses[variant]?.dark?.hover,
variantClasses[variant]?.dark?.active,
variantClasses[variant]?.dark.disabled,
disabled ? "s-cursor-default" : "",
className
);
Expand All @@ -155,6 +157,20 @@ export function Button({
>
{icon && <Icon visual={icon} size={size as IconProps["size"]} />}
<div className={finalContainerClasses}>{label}</div>
{type === "menu" && (
<Icon
className="s-opacity-50"
visual={ChevronDown}
size={size as IconProps["size"]}
/>
)}
{type === "select" && (
<Icon
className="s-opacity-60"
visual={ChevronUpDown}
size={size as IconProps["size"]}
/>
)}
</button>
) : (
<Tooltip label={label} position={tooltipPosition}>
Expand Down
8 changes: 5 additions & 3 deletions sparkle/src/components/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
useState,
} from "react";

import { ChevronDown } from "@sparkle/icons/solid";
import { ChevronDown, ChevronUpDown } from "@sparkle/icons/solid";
import { classNames } from "@sparkle/lib/utils";

import { Icon } from "./Icon";
Expand Down Expand Up @@ -76,6 +76,7 @@ export function DropdownMenu({ children, className = "" }: DropdownMenuProps) {

export interface DropdownButtonProps {
label?: string;
type?: "menu" | "select";
tooltip?: string;
tooltipPosition?: TooltipProps["position"];
icon?: ComponentType;
Expand All @@ -86,6 +87,7 @@ export interface DropdownButtonProps {

DropdownMenu.Button = function ({
label,
type = "menu",
tooltip,
icon,
children,
Expand Down Expand Up @@ -160,7 +162,7 @@ DropdownMenu.Button = function ({
>
<Icon visual={icon} size="sm" className={finalIconClasses} />
<Icon
visual={ChevronDown}
visual={type === "select" ? ChevronUpDown : ChevronDown}
size="xs"
className={finalChevronClasses}
/>
Expand All @@ -180,7 +182,7 @@ DropdownMenu.Button = function ({
<Icon visual={icon} size="sm" className={finalIconClasses} />
<span className={finalLabelClasses}>{label}</span>
<Icon
visual={ChevronDown}
visual={type === "select" ? ChevronUpDown : ChevronDown}
size="xs"
className={finalChevronClasses}
/>
Expand Down
18 changes: 18 additions & 0 deletions sparkle/src/icons/solid/ChevronUpDown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { SVGProps } from "react";
import * as React from "react";
const SvgChevronUpDown = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
fill="none"
viewBox="0 0 24 24"
{...props}
>
<path
fill="currentColor"
d="M8.5 11 12 7.5l3.5 3.5 2-2L12 3.5 6.5 9l2 2ZM15.5 13 12 16.5 8.5 13l-2 2 5.5 5.5 5.5-5.5-2-2Z"
/>
</svg>
);
export default SvgChevronUpDown;
1 change: 1 addition & 0 deletions sparkle/src/icons/solid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as ChevronDown } from "./ChevronDown";
export { default as ChevronLeft } from "./ChevronLeft";
export { default as ChevronRight } from "./ChevronRight";
export { default as ChevronUp } from "./ChevronUp";
export { default as ChevronUpDown } from "./ChevronUpDown";
export { default as Clipboard } from "./Clipboard";
export { default as ClipboardCheck } from "./ClipboardCheck";
export { default as Clock } from "./Clock";
Expand Down
4 changes: 4 additions & 0 deletions sparkle/src/icons/src/solid/chevron-up-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions sparkle/src/icons/src/stroke/chevron-up-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions sparkle/src/icons/stroke/ChevronUpDown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { SVGProps } from "react";
import * as React from "react";
const SvgChevronUpDown = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
fill="none"
viewBox="0 0 24 24"
{...props}
>
<path
fill="currentColor"
d="m9 11 3-3 3 3 1.5-1.5L12 5 7.5 9.5 9 11ZM15 13l-3 3-3-3-1.5 1.5L12 19l4.5-4.5L15 13Z"
/>
</svg>
);
export default SvgChevronUpDown;
1 change: 1 addition & 0 deletions sparkle/src/icons/stroke/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as ChevronDown } from "./ChevronDown";
export { default as ChevronLeft } from "./ChevronLeft";
export { default as ChevronRight } from "./ChevronRight";
export { default as ChevronUp } from "./ChevronUp";
export { default as ChevronUpDown } from "./ChevronUpDown";
export { default as Clipboard } from "./Clipboard";
export { default as ClipboardCheck } from "./ClipboardCheck";
export { default as Clock } from "./Clock";
Expand Down
Loading

0 comments on commit 8878dd0

Please sign in to comment.