mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-28 12:23:24 +01:00
migrated embed
This commit is contained in:
98 files changed
+1979
-1376
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { EmbedConfigItem } from '.';
|
||||
import type { EmbedConfigItem } from ".";
|
||||
|
||||
export enum EmbedItemType {
|
||||
Radius,
|
||||
@@ -12,16 +12,14 @@ export enum EmbedItemType {
|
||||
Enum,
|
||||
}
|
||||
|
||||
export const radixGrays = [
|
||||
'gray',
|
||||
'mauve',
|
||||
'slate',
|
||||
'sage',
|
||||
'olive',
|
||||
'sand',
|
||||
export const grays = [
|
||||
"gray",
|
||||
"mauve",
|
||||
"slate",
|
||||
"sage",
|
||||
"olive",
|
||||
"sand",
|
||||
] as const;
|
||||
|
||||
export const radixTextWeights = ['light', 'regular', 'medium', 'bold'] as const;
|
||||
|
||||
export type EmbedConfigItemType<Type extends EmbedItemType> =
|
||||
EmbedConfigItem & { type: Type };
|
||||
@@ -1,25 +1,26 @@
|
||||
import * as radixColors from "@radix-ui/colors";
|
||||
import { Soapstone } from "soapstone";
|
||||
import type { Color } from "../../ui/color";
|
||||
import type {
|
||||
Radius,
|
||||
Space,
|
||||
SpaceWithout0,
|
||||
Weight,
|
||||
} from "../../types/styles";
|
||||
import {
|
||||
type EmbedConfigItemType,
|
||||
EmbedItemType,
|
||||
radixGrays,
|
||||
radixTextWeights,
|
||||
grays,
|
||||
} from "./constants";
|
||||
|
||||
export type RadixSize = `${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`;
|
||||
export type RadixSizeWithout0 = Exclude<RadixSize, "0">;
|
||||
export type RadixRadius = `${1 | 2 | 3 | 4}` | "full";
|
||||
export type RadixTextWeight = (typeof radixTextWeights)[number];
|
||||
export type RadixColorCompound = {
|
||||
base: RadixColor;
|
||||
variant: RadixColorVariant;
|
||||
export type ColorCompound = {
|
||||
base: Color;
|
||||
variant: ColorVariant;
|
||||
};
|
||||
export type RadixTextColor =
|
||||
| Exclude<RadixColor, RadixColorGrays>
|
||||
export type TextColor =
|
||||
| Exclude<Color, Gray>
|
||||
| "gray"
|
||||
| undefined;
|
||||
export type RadixColorVariantRaw = `${
|
||||
export type ColorStep = `${
|
||||
| 1
|
||||
| 2
|
||||
| 3
|
||||
@@ -32,12 +33,8 @@ export type RadixColorVariantRaw = `${
|
||||
| 10
|
||||
| 11
|
||||
| 12}`;
|
||||
export type RadixColorVariant = `${"" | "a"}${RadixColorVariantRaw}`;
|
||||
export type RadixColor = Exclude<
|
||||
keyof typeof radixColors,
|
||||
`${string}${"A" | "P3" | "Dark"}`
|
||||
>;
|
||||
export type RadixColorGrays = (typeof radixGrays)[number];
|
||||
export type ColorVariant = `${"" | "a"}${ColorStep}`;
|
||||
export type Gray = (typeof grays)[number];
|
||||
|
||||
export type ExtractEmbedConfigTypes<Config extends EmbedConfig> = {
|
||||
[Key in keyof Config]: ({
|
||||
@@ -67,15 +64,15 @@ export type EmbedConfigItem = (
|
||||
}
|
||||
| {
|
||||
type: EmbedItemType.Radius;
|
||||
default: RadixRadius;
|
||||
default: Radius;
|
||||
}
|
||||
| {
|
||||
type: EmbedItemType.Size;
|
||||
default: RadixSize;
|
||||
default: Space;
|
||||
}
|
||||
| {
|
||||
type: EmbedItemType.SizeWithout0;
|
||||
default: RadixSizeWithout0;
|
||||
default: SpaceWithout0;
|
||||
}
|
||||
| {
|
||||
type: EmbedItemType.Color;
|
||||
@@ -85,8 +82,8 @@ export type EmbedConfigItem = (
|
||||
type: EmbedItemType.RichText;
|
||||
default: {
|
||||
color: string;
|
||||
size: RadixSizeWithout0;
|
||||
weight: RadixTextWeight;
|
||||
size: SpaceWithout0;
|
||||
weight: Weight;
|
||||
};
|
||||
}
|
||||
| {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { CSSProperties } from "react";
|
||||
import type { Radius, Space, SpaceWithout0, Weight } from "../../types/styles";
|
||||
|
||||
export interface EmbedRichText {
|
||||
color: string;
|
||||
size: SpaceWithout0;
|
||||
weight: Weight;
|
||||
}
|
||||
|
||||
export function embedSpace(size: Space) {
|
||||
return `var(--space-${size})`;
|
||||
}
|
||||
|
||||
export function embedRadius(radius: Radius) {
|
||||
if (radius === "full") return "var(--radius-max)";
|
||||
return embedSpace(radius);
|
||||
}
|
||||
|
||||
export function embedText({ color, size, weight }: EmbedRichText) {
|
||||
return {
|
||||
color,
|
||||
fontSize: embedSpace(size),
|
||||
fontWeight: `var(--weight-${weight})`,
|
||||
} satisfies CSSProperties;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { TextProps } from "@radix-ui/themes";
|
||||
import { EmbedState, type EmbedConfig, type ExtractEmbedConfigTypes } from ".";
|
||||
import {
|
||||
breakdownConfig,
|
||||
extractEmbedConfigDefaults,
|
||||
} from "../../constants/embeds";
|
||||
import type { EmbedConfigItemType, EmbedItemType } from "./constants";
|
||||
import { embedText } from "./tokens";
|
||||
|
||||
export function useEmbedStateCurry<Config extends EmbedConfig>() {
|
||||
// TODO: find a way to initialize with the correct state preset
|
||||
@@ -23,14 +23,11 @@ export function useEmbedStateCurry<Config extends EmbedConfig>() {
|
||||
: never;
|
||||
}[keyof Config],
|
||||
>(key: Key) {
|
||||
const { color, ...state } = useEmbedState(
|
||||
const state = useEmbedState(
|
||||
key,
|
||||
) as EmbedConfigItemType<EmbedItemType.RichText>["default"];
|
||||
|
||||
return {
|
||||
style: { color },
|
||||
...state,
|
||||
} satisfies TextProps;
|
||||
return embedText(state);
|
||||
}
|
||||
|
||||
return { useEmbedState, useRichText };
|
||||
|
||||
Reference in new issue
Block a user