Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to core, ui #429

Merged
merged 19 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
41a3eb3
[uma-bridge] Consolidate IconWithCircleBackground (#12761)
coreymartin Oct 9, 2024
72de9cc
[uma-bridge] Add UmaCard and variants. Add ClipboardTextFieldNode (#1…
coreymartin Oct 9, 2024
a43ca7a
CI update lock file for PR
Oct 9, 2024
06b9903
Update from public js-sdk main branch (#12656)
lightspark-ci-js-sdk[bot] Oct 10, 2024
efa2384
CI update lock file for PR
Oct 10, 2024
d946531
[site] Fix typography for WalletActionPreview (#12836)
coreymartin Oct 10, 2024
a562888
[uma-bridge] Move transactions activity to home page (#12763)
coreymartin Oct 10, 2024
3b8de74
[ui] Enable single defaultTypography argument for setDefaultTypograph…
coreymartin Oct 11, 2024
eadb3e0
[ui] Move CardForm description typography to theme (#12857)
coreymartin Oct 11, 2024
9b4f064
[ui] Add typed iconProps to Icon (#12880)
coreymartin Oct 14, 2024
69f8fec
[ui] add padding and outline props to TextInput (#12851)
bsiaotickchong Oct 14, 2024
0ebf657
[ui] add button click and hover colors (#12871)
bsiaotickchong Oct 14, 2024
3778e9a
[ui] add Inter font for uma auth sdk themes (#12905)
bsiaotickchong Oct 15, 2024
cc944aa
[ui] add floating Drawer kind and adjust closeButton size (#12911)
bsiaotickchong Oct 16, 2024
ced503d
[ui] add path props to most icons (#12933)
bsiaotickchong Oct 16, 2024
f80b616
[ui] add new icons (#12936)
bsiaotickchong Oct 16, 2024
a8746c4
[ui] add icon object prop instead of icon name to Button (#12956)
bsiaotickchong Oct 17, 2024
1fc2c59
Create many-humans-sneeze.md
bsiaotickchong Oct 17, 2024
4f41b46
Create curvy-queens-join.md
bsiaotickchong Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/curvy-queens-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@lightsparkdev/ui": patch
---

- update ClipboardTextField
- Fix line height typography
- Enable single defaultTypography argument for setDefaultTypography
- Move CardForm description typography to theme
- Add typed iconProps to Icon
- add padding and outline props to TextInput
- add button active and hover colors
- add Inter font for uma auth sdk themes
- add floating Drawer kind and adjust closeButton size
- add path props to most icons
- add new icons
- add icon object prop instead of icon name to Button
5 changes: 5 additions & 0 deletions .changeset/many-humans-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lightsparkdev/core": patch
---

- add RequiredKeys type utility
5 changes: 1 addition & 4 deletions apps/examples/ui-test-app/src/tests/toReactNodes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,7 @@ describe("toReactNodes", () => {
} as const;
const nodes = setDefaultReactNodesTypography(
[stringNode, linkNode, textNode],
{
link: defaultTypography,
text: defaultTypography,
},
{ default: defaultTypography },
);

expect(nodes).toEqual([
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

/* Opposite of Partial - make all keys required with NonNullable values */
export type Complete<T> = { [P in keyof T]-?: NonNullable<T[P]> };

/**
* RequiredKeys utility extracts all the keys of T that are required.
* For each key K in T, it checks if Pick<T, K> extends {} (an empty object). If it does, that
* means K is optional; otherwise, it's required.
* The resulting type is a union of all required keys in T.
*/
export type RequiredKeys<T> = {
[K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
}[keyof T];
13 changes: 3 additions & 10 deletions packages/ui/src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,9 @@ export function Badge({
color: typographyProp?.color || (kind === "danger" ? "danger" : "text"),
} as const;

const defaultTypographyMap = {
link: defaultTypography,
text: defaultTypography,
nextLink: defaultTypography,
};

const nodesWithTypography = setDefaultReactNodesTypography(
contentProp,
defaultTypographyMap,
);
const nodesWithTypography = setDefaultReactNodesTypography(contentProp, {
default: defaultTypography,
});

const content = toReactNodes(nodesWithTypography);

Expand Down
39 changes: 35 additions & 4 deletions packages/ui/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { applyTypography } from "../styles/typography.js";
import { type NewRoutesType } from "../types/index.js";
import { select } from "../utils/emotion.js";
import { Icon } from "./Icon/Icon.js";
import { type IconName } from "./Icon/types.js";
import { Loading, type LoadingKind } from "./Loading.js";
import { Tooltip } from "./Tooltip.js";
import { UnstyledButton } from "./UnstyledButton.js";
Expand All @@ -35,11 +34,14 @@ export const buttonKinds = [
"secondary",
"primary",
"ghost",
"transparent",
"green33",
"purple55",
"blue43",
"blue39",
"linkLight",
"danger",
"warning",
"tertiary",
] as const;
export type ButtonKind = (typeof buttonKinds)[number];
Expand All @@ -57,7 +59,9 @@ export type ButtonProps = {
externalLink?: string | undefined;
filename?: string | undefined;
toParams?: RouteParams | undefined;
icon?: IconName | undefined;
icon?:
| Pick<ComponentProps<typeof Icon>, "name" | "color" | "iconProps">
| undefined;
iconSide?: IconSide;
loading?: boolean | undefined;
loadingKind?: LoadingKind | undefined;
Expand Down Expand Up @@ -125,7 +129,9 @@ function resolveBackgroundColorKey(
| "defaultBackgroundColor"
| "defaultHoverBackgroundColor"
| "defaultBorderColor"
| "defaultHoverBorderColor",
| "defaultHoverBorderColor"
| "defaultActiveBackgroundColor"
| "defaultActiveBorderColor",
) {
const defaultBackgroundColorKey = theme.buttons.kinds[kind]?.[defaultKey];
let backgroundColorKey = defaultBackgroundColorKey;
Expand Down Expand Up @@ -191,6 +197,16 @@ function resolveProps(props: ButtonProps, theme: Theme) {
kind,
"defaultHoverBorderColor",
);
const activeBackgroundColor = resolveBackgroundColorKey(
theme,
kind,
"defaultActiveBackgroundColor",
);
const activeBorderColor = resolveBackgroundColorKey(
theme,
kind,
"defaultActiveBorderColor",
);

const typography = {
type:
Expand All @@ -215,6 +231,8 @@ function resolveProps(props: ButtonProps, theme: Theme) {
borderColor,
hoverBackgroundColor,
hoverBorderColor,
activeBackgroundColor,
activeBorderColor,
};
}

Expand All @@ -238,6 +256,8 @@ export function Button(props: ButtonProps) {
borderColor,
hoverBackgroundColor,
hoverBorderColor,
activeBackgroundColor,
activeBorderColor,
iconSide = "left",
loading = false,
loadingKind = "primary",
Expand Down Expand Up @@ -275,7 +295,7 @@ export function Button(props: ButtonProps) {
typography={typography}
kind={kind}
>
<Icon name={icon} width={iconSize} color={typography.color} />
<Icon {...icon} width={iconSize} color={typography.color} />
</ButtonIcon>
);
}
Expand Down Expand Up @@ -329,6 +349,8 @@ export function Button(props: ButtonProps) {
borderColor,
hoverBackgroundColor,
hoverBorderColor,
activeBackgroundColor,
activeBorderColor,
isRound: isSingleCharRoundButton,
isLoading: loading,
disabled: disabled || loading,
Expand Down Expand Up @@ -380,6 +402,8 @@ type StyledButtonProps = {
borderColor: string;
hoverBackgroundColor: string;
hoverBorderColor: string;
activeBackgroundColor: string;
activeBorderColor: string;
css: { marginTop: string | undefined; marginLeft: string | undefined };
borderRadius: ButtonBorderRadius;
iconSide: IconSide;
Expand All @@ -402,6 +426,8 @@ const buttonStyle = ({
backgroundColor,
hoverBackgroundColor,
hoverBorderColor,
activeBackgroundColor,
activeBorderColor,
}: StyledButtonProps & { theme: Theme }) => {
const borderColor = borderColorProp || backgroundColor;

Expand Down Expand Up @@ -452,6 +478,11 @@ const buttonStyle = ({
background-color: ${hoverBackgroundColor};
border-color: ${hoverBorderColor};
}

&:active {
background-color: ${activeBackgroundColor};
border-color: ${activeBorderColor};
}
}
`;
};
Expand Down
68 changes: 27 additions & 41 deletions packages/ui/src/components/CardForm/CardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,7 @@ import { TextInputHalfRow } from "../TextInput.js";
import { ToggleContainer } from "../Toggle.js";
import { Headline } from "../typography/Headline.js";

const descriptionTypography = {
primary: {
text: {
type: "Body Strong",
size: "Small",
color: "mcNeutral",
},
link: {
type: "Body Strong",
size: "Small",
color: "text",
},
},
secondary: {
text: {
type: "Body Strong",
size: "Small",
color: "mcNeutral",
},
link: {
type: "Body Strong",
size: "Small",
color: "text",
},
},
tertiary: {
text: {
type: "Body",
size: "Large",
color: "mcNeutral",
},
link: {
type: "Body",
size: "Large",
color: "text",
},
},
} as const;
type BelowCardFormContentGap = 0 | 16;

type CardFormProps = {
children?: ReactNode;
Expand All @@ -105,6 +68,7 @@ type CardFormProps = {
textAlign?: CardFormTextAlign;
shadow?: CardFormShadow;
belowFormContent?: ToReactNodesArgs | undefined;
belowFormContentGap?: BelowCardFormContentGap | undefined;
};

type ResolvePropsArgs = {
Expand Down Expand Up @@ -159,6 +123,12 @@ function resolveProps(args: ResolvePropsArgs, theme: Theme) {
"smBorderWidth",
theme,
);
const defaultDescriptionTypographyMap = resolveCardFormProp(
undefined,
args.kind,
"defaultDescriptionTypographyMap",
theme,
);

const props = {
paddingY,
Expand All @@ -171,6 +141,7 @@ function resolveProps(args: ResolvePropsArgs, theme: Theme) {
backgroundColor,
smBackgroundColor,
smBorderWidth,
defaultDescriptionTypographyMap,
};

return props;
Expand All @@ -192,6 +163,7 @@ export function CardForm({
shadow: shadowProp,
textAlign: textAlignProp,
belowFormContent,
belowFormContentGap = 0,
}: CardFormProps) {
const theme = useTheme();
const {
Expand All @@ -205,6 +177,7 @@ export function CardForm({
backgroundColor,
smBackgroundColor,
smBorderWidth,
defaultDescriptionTypographyMap,
} = resolveProps(
{ kind, textAlign: textAlignProp, shadow: shadowProp },
theme,
Expand All @@ -224,7 +197,10 @@ export function CardForm({
);

const formattedDescription = description
? toReactNodesWithTypographyMap(description, descriptionTypography[kind])
? toReactNodesWithTypographyMap(
description,
defaultDescriptionTypographyMap,
)
: null;

const belowFormContentNodes = belowFormContent
Expand Down Expand Up @@ -277,7 +253,9 @@ export function CardForm({
{content}
</StyledCardForm>
)}
<BelowCardFormContent>{belowFormContentNodes}</BelowCardFormContent>
<BelowCardFormContent gap={belowFormContentGap}>
{belowFormContentNodes}
</BelowCardFormContent>
</CardFormContainer>
);
}
Expand All @@ -297,9 +275,17 @@ const CardFormContent = styled.div`
align-self: center;
`;

const BelowCardFormContent = styled.div`
type BelowCardFormContentProps = {
gap: BelowCardFormContentGap;
};

const BelowCardFormContent = styled.div<BelowCardFormContentProps>`
text-align: center;
margin-top: 32px;
display: flex;
align-items: center;
justify-content: center;
gap: ${({ gap }) => gap}px;

${bp.sm(`
margin-bottom: 32px;
Expand Down
13 changes: 3 additions & 10 deletions packages/ui/src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,9 @@ export function Checkbox({
color: typographyProp?.color || "text",
} as const;

const defaultTypographyMap = {
link: defaultTypography,
text: defaultTypography,
nextLink: defaultTypography,
};

const nodesWithTypography = setDefaultReactNodesTypography(
label,
defaultTypographyMap,
);
const nodesWithTypography = setDefaultReactNodesTypography(label, {
default: defaultTypography,
});

const content = toReactNodes(nodesWithTypography);

Expand Down
Loading
Loading