feat: complete select

main
Juan Olvera 11 months ago
parent c396bc69fb
commit ccfdecb318

@ -751,12 +751,12 @@ select {
right: 0.75rem; right: 0.75rem;
} }
.isolate { .right-2 {
isolation: isolate; right: 0.5rem;
} }
.z-50 { .isolate {
z-index: 50; isolation: isolate;
} }
.m-0 { .m-0 {
@ -799,10 +799,6 @@ select {
height: 2px; height: 2px;
} }
.h-10 {
height: 2.5rem;
}
.max-h-96 { .max-h-96 {
max-height: 24rem; max-height: 24rem;
} }
@ -922,6 +918,10 @@ select {
border-radius: 0.375rem; border-radius: 0.375rem;
} }
.rounded-sm {
border-radius: 0.125rem;
}
.border-2 { .border-2 {
border-width: 2px; border-width: 2px;
} }
@ -1074,14 +1074,6 @@ select {
padding-right: 0.75rem; padding-right: 0.75rem;
} }
.pr-2 {
padding-right: 0.5rem;
}
.pl-8 {
padding-left: 2rem;
}
.text-left { .text-left {
text-align: left; text-align: left;
} }
@ -1142,12 +1134,6 @@ select {
opacity: 0; opacity: 0;
} }
.shadow-md {
--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.outline-none { .outline-none {
outline: 2px solid transparent; outline: 2px solid transparent;
outline-offset: 2px; outline-offset: 2px;
@ -1191,19 +1177,28 @@ html {
background-color: rgb(63 63 70 / var(--tw-bg-opacity)); background-color: rgb(63 63 70 / var(--tw-bg-opacity));
} }
.hover\:bg-mono-hover:hover { .focus\:rounded-md:focus {
border-radius: 0.375rem;
}
.focus\:border-mono-primary:focus {
--tw-border-opacity: 1;
border-color: rgb(39 39 42 / var(--tw-border-opacity));
}
.focus\:bg-mono-hover:focus {
--tw-bg-opacity: 1; --tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity)); background-color: rgb(229 231 235 / var(--tw-bg-opacity));
} }
.hover\:bg-mono-primary:hover { .focus\:bg-mono-primary:focus {
--tw-bg-opacity: 1; --tw-bg-opacity: 1;
background-color: rgb(39 39 42 / var(--tw-bg-opacity)); background-color: rgb(39 39 42 / var(--tw-bg-opacity));
} }
.focus\:border-mono-primary:focus { .focus\:text-white:focus {
--tw-border-opacity: 1; --tw-text-opacity: 1;
border-color: rgb(39 39 42 / var(--tw-border-opacity)); color: rgb(255 255 255 / var(--tw-text-opacity));
} }
.focus\:outline-none:focus { .focus\:outline-none:focus {
@ -1217,16 +1212,6 @@ html {
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
} }
.focus\:ring-2:focus {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
.focus\:ring-offset-2:focus {
--tw-ring-offset-width: 2px;
}
.focus-visible\:ring-2:focus-visible { .focus-visible\:ring-2:focus-visible {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
@ -1242,16 +1227,22 @@ html {
--tw-ring-offset-width: 2px; --tw-ring-offset-width: 2px;
} }
.disabled\:cursor-not-allowed:disabled { .data-\[disabled\]\:pointer-events-none[data-disabled] {
cursor: not-allowed; pointer-events: none;
} }
.disabled\:opacity-50:disabled { .data-\[highlighted\]\:border-2[data-highlighted] {
opacity: 0.5; border-width: 2px;
} }
.data-\[disabled\]\:pointer-events-none[data-disabled] { .data-\[highlighted\]\:border-mono-primary[data-highlighted] {
pointer-events: none; --tw-border-opacity: 1;
border-color: rgb(39 39 42 / var(--tw-border-opacity));
}
.data-\[highlighted\]\:bg-gray-400[data-highlighted] {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
} }
.data-\[disabled\]\:text-mono-text\/50[data-disabled] { .data-\[disabled\]\:text-mono-text\/50[data-disabled] {
@ -1262,6 +1253,11 @@ html {
opacity: 0.5; opacity: 0.5;
} }
.data-\[highlighted\]\:outline-none[data-highlighted] {
outline: 2px solid transparent;
outline-offset: 2px;
}
.data-\[focus\]\:outline[data-focus] { .data-\[focus\]\:outline[data-focus] {
outline-style: solid; outline-style: solid;
} }

@ -3,6 +3,7 @@ import dashify from "dashify";
import { NumericFormat } from "react-number-format"; import { NumericFormat } from "react-number-format";
import type * as T from "./Input.types"; import type * as T from "./Input.types";
import { Box } from "../Box"; import { Box } from "../Box";
import { Label } from "../Label";
import { cx } from "../../utils"; import { cx } from "../../utils";
import { inputStyles } from "./Input.styles"; import { inputStyles } from "./Input.styles";
import { match, P } from "ts-pattern"; import { match, P } from "ts-pattern";
@ -42,17 +43,14 @@ const Input = React.forwardRef<HTMLInputElement, T.InputProps>(
return ( return (
<Box className={cx(["relative"])}> <Box className={cx(["relative"])}>
<label <Label
className={cx( className={cx({
["text-sm", "font-semibold", "leading-6", "text-mono-primary"],
{
"sr-only": hideLabel, "sr-only": hideLabel,
} })}
)}
htmlFor={htmlId} htmlFor={htmlId}
> >
{label} {label}
</label> </Label>
<Box <Box
className={cx(["relative"], { className={cx(["relative"], {
"mt-1": !hideLabel, "mt-1": !hideLabel,

@ -0,0 +1,28 @@
import * as React from "react";
import * as $ from "@radix-ui/react-label";
import { cva } from "class-variance-authority";
import { cx } from "../utils";
type LabelElement = React.ElementRef<typeof $.Root>;
type LabelProps = React.ComponentPropsWithoutRef<typeof $.Root>;
const styles = cva([
"text-sm",
"font-semibold",
"leading-6",
"text-mono-primary",
]);
const Label = React.forwardRef<LabelElement, LabelProps>(
({ children, ...props }, forwardRef) => {
const classes = cx(styles(), props.className);
return (
<$.Root {...props} className={classes} ref={forwardRef}>
{children}
</$.Root>
);
}
);
export { Label };

@ -19,8 +19,8 @@ const content = [
"relative", "relative",
"max-h-96", "max-h-96",
"min-w-[8rem]", "min-w-[8rem]",
"py-1.5", // "py-1.5",
"px-2", // "px-2",
"border-2", "border-2",
"border-mono-border", "border-mono-border",
"overflow-hidden", "overflow-hidden",
@ -50,13 +50,24 @@ const scroll = [
const indicator = [ const indicator = [
"absolute", "absolute",
"left-0", "top-1/2",
"-translate-y-1/2",
"right-2",
"inline-flex", "inline-flex",
"items-center", "items-center",
"justify-center", "justify-center",
]; ];
const selectStyles = cva(base); const selectStyles = cva(base, {
variants: {
fullWidth: {
true: "w-full",
},
},
defaultVariants: {
fullWidth: false,
},
});
const item = [ const item = [
"relative", "relative",
@ -65,12 +76,15 @@ const item = [
"cursor-default", "cursor-default",
"select-none", "select-none",
"items-center", "items-center",
"py-1.5", "py-0.5",
"pr-2", "px-2",
"pl-8", "rounded-sm",
"data-[disabled]:pointer-events-none", "data-[disabled]:pointer-events-none",
"data-[disabled]:text-mono-text/50", "data-[disabled]:text-mono-text/50",
"focus:outline-none", "outline-none",
"focus:rounded-md",
"focus:bg-mono-primary",
"focus:text-white",
"focus:border-mono-primary", "focus:border-mono-primary",
]; ];

@ -1,20 +1,26 @@
import * as React from "react"; import * as React from "react";
import * as $ from "@radix-ui/react-select"; import * as $ from "@radix-ui/react-select";
import { Label } from "@radix-ui/react-label";
import { FaCheck, FaChevronDown, FaChevronUp } from "react-icons/fa"; import { FaCheck, FaChevronDown, FaChevronUp } from "react-icons/fa";
import * as T from "./Select.types"; import * as T from "./Select.types";
import * as styles from "./Select.styles"; import * as styles from "./Select.styles";
import { cx } from "../../utils"; import { cx } from "../../utils";
import { Box } from "../Box"; import { Box } from "../Box";
import { Label } from "../Label";
const Select = React.forwardRef<T.SelectElement, T.SelectProps>( const Select = React.forwardRef<T.SelectElement, T.SelectProps>(
({ children, className, ...props }, ref) => { ({ hideLabel = false, fullWidth, children, className, ...props }, ref) => {
const classes = cx([styles.selectStyles()], className); const classes = cx([styles.selectStyles({ fullWidth })], className);
console.log("classes", classes);
return ( return (
<Box> <Box className={cx(["relative"])}>
<Label htmlFor={"select"}>Select</Label> <Label
<Box> htmlFor={"select"}
className={cx([""], {
"sr-only": hideLabel,
})}
>
Select
</Label>
<Box className={cx(["mt-1"])}>
<$.Root> <$.Root>
<$.Trigger id="select" {...props} className={classes} ref={ref}> <$.Trigger id="select" {...props} className={classes} ref={ref}>
<$.Value placeholder={props.placeholder} /> <$.Value placeholder={props.placeholder} />
@ -49,7 +55,7 @@ const SelectItem = React.forwardRef<T.SelectItemElement, T.SelectItemProps>(
({ children, className, ...props }, forwardedRef) => { ({ children, className, ...props }, forwardedRef) => {
const classes = cx([styles.itemStyles()], className); const classes = cx([styles.itemStyles()], className);
return ( return (
<$.Item {...props} ref={forwardedRef}> <$.Item {...props} className={classes} ref={forwardedRef}>
<$.ItemText>{children}</$.ItemText> <$.ItemText>{children}</$.ItemText>
<$.ItemIndicator className={cx([styles.indicator])}> <$.ItemIndicator className={cx([styles.indicator])}>
<FaCheck /> <FaCheck />

@ -16,7 +16,9 @@ type SelectSection = {
type SelectElement = React.ElementRef<typeof $.Trigger>; type SelectElement = React.ElementRef<typeof $.Trigger>;
type SelectProps = React.ComponentPropsWithoutRef<typeof $.Trigger> & type SelectProps = React.ComponentPropsWithoutRef<typeof $.Trigger> &
VariantProps<typeof selectStyles> & {}; VariantProps<typeof selectStyles> & {
hideLabel?: boolean;
};
type SelectItemElement = React.ElementRef<typeof $.Item>; type SelectItemElement = React.ElementRef<typeof $.Item>;

@ -29,7 +29,7 @@ module.exports = {
DEFAULT: colors.gray["500"], DEFAULT: colors.gray["500"],
}, },
"mono-hover": { "mono-hover": {
DEFAULT: colors.gray[400], DEFAULT: colors.gray[200],
}, },
"mono-rounded": { "mono-rounded": {
DEFAULT: defaultTheme.borderRadius["lg"], DEFAULT: defaultTheme.borderRadius["lg"],

Loading…
Cancel
Save