Skip to content

Commit

Permalink
chore: hide or disable select based on content (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
morekid authored Nov 21, 2024
1 parent 7382fa7 commit 15e87df
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/SDKVersionBun.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<picture>
<picture class="badge">
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
2 changes: 1 addition & 1 deletion src/components/SDKVersionNextjs.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<picture>
<picture class="badge">
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
2 changes: 1 addition & 1 deletion src/components/SDKVersionNodejs.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<picture>
<picture class="badge">
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
2 changes: 1 addition & 1 deletion src/components/SDKVersionSvelteKit.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<picture>
<picture class="badge">
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
27 changes: 19 additions & 8 deletions src/components/Select.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--primary-plain-activeColor: var(--aj-palette-source-white);
--primary-plain-activeBorder: 1px solid
rgba(var(--aj-palette-source-neutralRgb-07) / 0.3);
--primary-plain-disabledBg: rgba(var(--aj-palette-source-whiteRgb) / 0.04);
--primary-plain-disabledColor: var(--aj-palette-source-neutral-03);

--secondary-solid-idleBg: rgba(var(--aj-palette-source-whiteRgb) / 0.06);
Expand All @@ -18,6 +19,9 @@
--secondary-plain-activeColor: var(--aj-palette-source-neutral-15);
--secondary-plain-activeBorder: 1px solid
rgba(var(--aj-palette-source-neutralRgb-07) / 0.3);
--secondary-plain-disabledBg: rgba(
var(--aj-palette-source-whiteRgb) / 0.02
);
--secondary-plain-disabledColor: var(--aj-palette-source-neutral-03);
}
}
Expand All @@ -31,8 +35,10 @@
--primary-plain-activeColor: var(--aj-palette-source-black);
--primary-plain-activeBorder: 1px solid
rgba(var(--aj-palette-source-neutralRgb-08) / 0.3);
--primary-plain-disabledBg: rgba(var(--aj-palette-source-blackRgb) / 0.04);
--primary-plain-disabledColor: var(--aj-palette-source-neutral-12);

--secondary-solid-idleBg: rgba(var(--aj-palette-source-whiteRgb) / 0.06);
--secondary-plain-idleColor: var(--aj-palette-source-neutral-04);
--secondary-plain-hoverBg: rgba(
var(--aj-palette-source-neutralRgb-12) / 0.3
Expand All @@ -41,6 +47,9 @@
--secondary-plain-activeColor: var(--aj-palette-source-neutral-00);
--secondary-plain-activeBorder: 1px solid
rgba(var(--aj-palette-source-neutralRgb-08) / 0.3);
--secondary-plain-disabledBg: rgba(
var(--aj-palette-source-whiteRgb) / 0.02
);
--secondary-plain-disabledColor: var(--aj-palette-source-neutral-12);
}
}
Expand Down Expand Up @@ -96,9 +105,9 @@
--trigger-border: var(--primary-plain-activeBorder);
}

&:disabled {
--trigger-color: var(--primary-plainColor);
--trigger-bg: transparent;
&.Disabled {
--trigger-color: var(--primary-plain-disabledColor);
--trigger-bg: var(--primary-plain-disabledBg);
--trigger-border: none;
}

Expand Down Expand Up @@ -128,9 +137,9 @@
--trigger-border: var(--secondary-plain-activeBorder);
}

&:disabled {
--trigger-color: var(--secondary-plainColor);
--trigger-bg: transparent;
&.Disabled {
--trigger-color: var(--secondary-plain-disabledColor);
--trigger-bg: var(--secondary-plain-disabledBg);
--trigger-border: none;
}

Expand Down Expand Up @@ -240,7 +249,9 @@
line-height: 18px;
}

&:disabled {
cursor: default;
&.Disabled {
.Select {
cursor: default;
}
}
}
3 changes: 3 additions & 0 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Select = forwardRef(
onChange,
onFocus,
onBlur,
disabled,
...props
}: Props,
ref: ForwardedRef<HTMLSelectElement>,
Expand Down Expand Up @@ -114,6 +115,7 @@ const Select = forwardRef(
if (trigger.size)
clsWrapper +=
" Size-" + trigger.size + " " + styles["Size-" + trigger.size];
if (disabled) clsWrapper += " " + styles.Disabled;

let cls = "Select " + styles.Select;

Expand All @@ -132,6 +134,7 @@ const Select = forwardRef(
onFocus={handleFocus}
onBlur={handleBlur}
onChange={handleChange}
disabled={disabled}
{...props}
>
{props.children}
Expand Down
9 changes: 5 additions & 4 deletions src/components/SelectableContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ const SelectableContent = ({
children,
...props
}: Props) => {
let cls = "SelectableContent " + styles.SelectableContent;
if (className) cls += " " + className;

const [selectedSlot, setSelectedSlot] = useState<Slot>();
const [slots, setSlots] = useState<Slot[]>();

Expand Down Expand Up @@ -107,17 +104,21 @@ const SelectableContent = ({
}
}, [storedSyncKeyValue]);

let cls = "SelectableContent " + styles.SelectableContent;
if (className) cls += " " + className;

// TODO: sync sync key with nano store

return (
<div className={cls}>
<div className={styles.Toolbar}>
{slots && (
{slots && (slots.length > 1 || syncKey == "language") && (
<Select
onChange={onChange}
value={selectedSlot?.key}
trigger={{ size: "sm" }}
level="secondary"
disabled={slots.length <= 1 && syncKey == "language"}
>
{slots.map((slot: Slot, idx: number) => {
return (
Expand Down
4 changes: 4 additions & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,7 @@ h6,
padding-block: clamp(2.5rem, calc(1rem + 6vmin), 6rem);
}
}

.sl-markdown-content .badge img {
margin-top: 0px;
}

0 comments on commit 15e87df

Please sign in to comment.