base
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
import { clsx } from "clsx";
|
||||
import type { ClassValue } from "clsx";
|
||||
|
||||
import { extendTailwindMerge } from "tailwind-merge";
|
||||
|
||||
// Support email can be configured by the application
|
||||
export const getSupportEmail = (defaultEmail: string = ""): string => defaultEmail;
|
||||
|
||||
// Matches custom typography classes: text-h1-semibold, text-body-md-regular, text-caption-xs-medium, etc.
|
||||
const isCustomTypography = (value: string) =>
|
||||
!/^(h[1-6]|body-(xs|sm|md)|caption-(xs|sm|md))-(regular|medium|semibold|bold)$/.test(value);
|
||||
|
||||
// Matches custom font size classes: text-9, text-10, text-11, text-12, text-13, text-14, text-16, text-18, text-20, text-24, text-28, text-32, text-40
|
||||
const isCustomFontSize = (value: string) => /^(9|10|11|12|13|14|16|18|20|24|28|32|40)$/.test(value);
|
||||
|
||||
// Matches custom text color classes: text-primary, text-on-color, text-secondary, etc.
|
||||
const CUSTOM_TEXT_COLORS = [
|
||||
"primary",
|
||||
"secondary",
|
||||
"tertiary",
|
||||
"placeholder",
|
||||
"disabled",
|
||||
"accent-primary",
|
||||
"accent-secondary",
|
||||
"on-color",
|
||||
"on-color-disabled",
|
||||
"inverse",
|
||||
"success",
|
||||
"success-primary",
|
||||
"success-secondary",
|
||||
"warning",
|
||||
"warning-primary",
|
||||
"warning-secondary",
|
||||
"danger",
|
||||
"danger-primary",
|
||||
"danger-secondary",
|
||||
];
|
||||
const isCustomTextColor = (value: string) => CUSTOM_TEXT_COLORS.includes(value);
|
||||
|
||||
const twMerge = extendTailwindMerge<"custom-typography" | "custom-text-color">({
|
||||
override: {
|
||||
classGroups: {
|
||||
// Override font-size to include custom numeric sizes and exclude custom typography/colors
|
||||
"font-size": [
|
||||
{
|
||||
text: [
|
||||
(value: string) => isCustomFontSize(value) || (!isCustomTypography(value) && !isCustomTextColor(value)),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
extend: {
|
||||
classGroups: {
|
||||
// Custom typography in its own group
|
||||
"custom-typography": [{ text: [isCustomTypography] }],
|
||||
// Custom text colors in their own group (won't conflict with font sizes)
|
||||
"custom-text-color": [{ text: [isCustomTextColor] }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
export * from "./classname";
|
||||
export * from "./placement";
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
// types
|
||||
export type TPlacement =
|
||||
| "auto"
|
||||
| "auto-start"
|
||||
| "auto-end"
|
||||
| "top-start"
|
||||
| "top-end"
|
||||
| "bottom-start"
|
||||
| "bottom-end"
|
||||
| "right-start"
|
||||
| "right-end"
|
||||
| "left-start"
|
||||
| "left-end"
|
||||
| "top"
|
||||
| "bottom"
|
||||
| "right"
|
||||
| "left";
|
||||
|
||||
export type TSide = "top" | "bottom" | "left" | "right";
|
||||
export type TAlign = "start" | "center" | "end";
|
||||
|
||||
// placement conversion map
|
||||
const PLACEMENT_MAP = new Map<TPlacement, { side: TSide; align: TAlign }>([
|
||||
["auto", { side: "bottom", align: "center" }],
|
||||
["auto-start", { side: "bottom", align: "start" }],
|
||||
["auto-end", { side: "bottom", align: "end" }],
|
||||
["top", { side: "top", align: "center" }],
|
||||
["bottom", { side: "bottom", align: "center" }],
|
||||
["left", { side: "left", align: "center" }],
|
||||
["right", { side: "right", align: "center" }],
|
||||
["top-start", { side: "top", align: "start" }],
|
||||
["top-end", { side: "top", align: "end" }],
|
||||
["bottom-start", { side: "bottom", align: "start" }],
|
||||
["bottom-end", { side: "bottom", align: "end" }],
|
||||
["left-start", { side: "left", align: "start" }],
|
||||
["left-end", { side: "left", align: "end" }],
|
||||
["right-start", { side: "right", align: "start" }],
|
||||
["right-end", { side: "right", align: "end" }],
|
||||
]);
|
||||
|
||||
// conversion function
|
||||
export function convertPlacementToSideAndAlign(placement: TPlacement): {
|
||||
side: TSide;
|
||||
align: TAlign;
|
||||
} {
|
||||
return PLACEMENT_MAP.get(placement) || { side: "bottom", align: "center" };
|
||||
}
|
||||
Reference in New Issue
Block a user