Skip to content

Commit

Permalink
♻️ #15 - refactor: refactor styling
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Feb 1, 2024
1 parent 02bf88f commit 1a7473b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 58 deletions.
12 changes: 2 additions & 10 deletions src/components/breadcrumbs/breadcrumbs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@
}
}

&__link {
cursor: pointer;
text-decoration: none;
color: inherit;
font-size: var(--typography-font-size-body-xs);
}

&__separator {
.mykn-icon {
color: var(--theme-color-primary-800);
height: 20px;
width: 20px;
margin: 0 var(--spacing-h-xs);
}
}
18 changes: 5 additions & 13 deletions src/components/breadcrumbs/breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import clsx from "clsx";
import React from "react";

import { Outline } from "../icon";
Expand Down Expand Up @@ -37,28 +36,21 @@ export const Breadcrumbs: React.FC<BreadcrumbsProps> = ({
}) => {
return (
<nav className="mykn-breadcrumbs" {...props}>
<Ol className="mykn-breadcrumbs__list">
<Ol inline listStyle="none">
{pathItems.map((item, index) => {
const isLastItem = index === pathItems.length - 1;

return (
<Li
key={item.path}
size="xs"
className={clsx("mykn-breadcrumbs__item", {
"mykn-breadcrumbs__item--last": isLastItem,
})}
>
<Li key={item.path} size="xs">
<A
href={item.path}
muted={!isLastItem}
textDecoration="none"
onClick={() => onClick?.(item.path)}
className="mykn-breadcrumbs__link"
>
{item.label}
</A>
{!isLastItem && (
<Outline.ChevronRightIcon className="mykn-breadcrumbs__separator" />
)}
{!isLastItem && <Outline.ChevronRightIcon />}
</Li>
);
})}
Expand Down
15 changes: 14 additions & 1 deletion src/components/typography/a/a.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
@use '../p/p';
@use "../p/p";

.mykn-a {
@extend .mykn-p;
color: var(--theme-color-primary-800);
display: inline-flex;
font-size: inherit;
justify-content: center;
align-items: center;
gap: 0.5em;
width: fit-content;

&--text-decoration-none {
text-decoration: none;

&#{&}:hover {
text-decoration: underline;
}
}

&:hover {
text-decoration: none;
}

&#{&}--muted {
@extend .mykn-p--muted;
}

&[aria-current] {
font-weight: var(--typography-font-weight-bold);
}
Expand Down
25 changes: 23 additions & 2 deletions src/components/typography/a/a.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from "clsx";
import React, { AnchorHTMLAttributes } from "react";

import "./a.scss";
Expand All @@ -8,17 +9,37 @@ export type AProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
* container or set of related elements.
*/
active?: boolean;

/** Whether the text should be presented in a lighter color. */
muted?: boolean;

/** The text decoration. */
textDecoration?: "underline" | "none";
};

/**
* Anchor (<a>) component
* @param active
* @param children
* @param muted
* @param textDecoration
* @param props
* @constructor
*/
export const A: React.FC<AProps> = ({ active, children, ...props }) => (
<a className="mykn-a" aria-current={active} {...props}>
export const A: React.FC<AProps> = ({
active,
children,
muted,
textDecoration = "underline",
...props
}) => (
<a
className={clsx("mykn-a", `mykn-a--text-decoration-${textDecoration}`, {
"mykn-a--muted": muted,
})}
aria-current={active}
{...props}
>
{children}
</a>
);
4 changes: 4 additions & 0 deletions src/components/typography/li/li.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

.mykn-li {
@extend .mykn-p;

&--size-xs {
@extend .mykn-p--size-xs;
}
}
26 changes: 6 additions & 20 deletions src/components/typography/li/li.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,20 @@ import React from "react";

import "./li.scss";

export type LiProps = React.PropsWithChildren<
{
/** The size of the text. */
size?: "s" | "xs";

/** Additional class names to apply to the component */
className?: string;
} & React.HTMLAttributes<HTMLLIElement>
>;
export type LiProps = React.HTMLAttributes<HTMLLIElement> & {
/** The size of the text. */
size?: "s" | "xs";
};

/**
* Li component
* @param children
* @param size
* @param className
* @param props
* @constructor
*/
export const Li: React.FC<LiProps> = ({
children,
size = "s",
className,
...props
}) => (
<li
className={clsx("mykn-li", `mykn-li--size-${size}`, className)}
{...props}
>
export const Li: React.FC<LiProps> = ({ children, size = "s", ...props }) => (
<li className={clsx("mykn-li", `mykn-li--size-${size}`)} {...props}>
{children}
</li>
);
9 changes: 9 additions & 0 deletions src/components/typography/ol/ol.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
list-style-position: inside;
padding-inline-start: 0;

&--inline .mykn-li {
float: left; // fallback
float: inline-start;
}

&--list-style-none {
list-style: none;
}

.mykn-ol {
padding-inline-start: var(--spacing-h-xl);
}
Expand Down
30 changes: 19 additions & 11 deletions src/components/typography/ol/ol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@ import React from "react";
import { PProps } from "../p";
import "./ol.scss";

export type OlProps = React.PropsWithChildren<
{
/** The size of the text. */
size?: PProps["size"];
export type OlProps = React.HTMLAttributes<HTMLOListElement> & {
/** Whether to show list items inline. */
inline?: boolean;

/** Additional class names to apply to the component */
className?: string;
} & React.HTMLAttributes<HTMLOListElement>
>;
/** The list style. */
listStyle?: "decimal" | "none";

/** The size of the text. */
size?: PProps["size"];
};

/**
* Ol component
* @param children
* @param inline
* @param listStyle
* @param size
* @param className
* @param props
* @constructor
*/
export const Ol: React.FC<OlProps> = ({
children,
inline = false,
listStyle,
size = "s",
className,
...props
}) => (
<ol
className={clsx("mykn-ol", `mykn-ol--size-${size}`, className)}
className={clsx(
"mykn-ol",
`mykn-ol--size-${size}`,
`mykn-ol--list-style-${listStyle}`,
{ "mykn-ol--inline": inline },
)}
{...props}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/components/typography/p/p.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type PProps = React.PropsWithChildren<{
/**
* Ul component
* @param children
* @param muted
* @param size
* @param props
* @constructor
Expand Down
2 changes: 1 addition & 1 deletion src/settings/tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
--typography-color-background: var(--theme-shade-0);
--typography-color-h: var(--theme-shade-900);
--typography-color-body: var(--theme-shade-700);
--typography-color-muted: var(--theme-shade-400);
--typography-color-muted: var(--theme-shade-600);

--typography-font-size-h1: 24px;
--typography-font-size-h2: 20px;
Expand Down

0 comments on commit 1a7473b

Please sign in to comment.