Skip to content

Commit

Permalink
feat(SkipLink): added styles as scss modules
Browse files Browse the repository at this point in the history
  • Loading branch information
João Dias committed Apr 21, 2024
1 parent f9fa4f9 commit 403280c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 39 deletions.
51 changes: 51 additions & 0 deletions src/components/skip-links/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
:global(.fdz-css-skip-links__item),
.item {
--skip-link-background: #111;
--skip-link-color: #fff;
--skip-link-font-family: sans-serif;
--skip-link-font-size: 0.875rem;
--skip-link-left: 2rem;
--skip-link-line-height: 2rem;
--skip-link-top: 1rem;
--skip-link-opacity: 1;
--skip-link-outline-color: var(--skip-link-background);

position: absolute;
top: var(--skip-link-top);
left: var(--skip-link-left);
right: auto;
font-size: var(--skip-link-font-size);
font-family: var(--skip-link-font-family);
background: var(--skip-link-background);
color: var(--skip-link-color);
display: flex;
justify-content: center;
align-items: center;
letter-spacing: 0.5px;
line-height: var(--skip-link-line-height);
padding: 0 1rem;
appearance: none;
text-align: center;
text-decoration: none;
height: 2rem;
min-width: 10rem;
z-index: 100;
outline-width: 2px;
outline-style: solid;
outline-color: var(--skip-link-outline-color);
outline-offset: 2px;
}

:global(.fdz-css-skip-links__item):not(:focus),
.item:not(:focus) {
border: 0;
clip: rect(0 0 0 0);
height: auto;
margin: 0;
overflow: hidden;
opacity: var(--skip-link-opacity);
padding: 0;
position: absolute !important;
width: 1px;
white-space: nowrap;
}
11 changes: 8 additions & 3 deletions src/components/skip-links/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* @since 1.0.0
*/
import React, { FunctionComponent, useCallback, KeyboardEvent } from "react";
import "./styles.css";
import { classNames, useConstant } from "@feedzai/js-utilities";
import styles from "./index.module.scss";

export const SKIP_LINK_DEFAULT_PROPS: ISkipLink = {
target: "#content",
Expand All @@ -33,6 +34,10 @@ export interface ISkipLink {
* @returns {JSX.Element}
*/
export const SkipLink: FunctionComponent<ISkipLink> = ({ target, text, as }) => {
const CSS_CLASS = useConstant(() => {
return classNames(styles.item, "fdz-css-skip-links__item");
});

const onKeyUp = useCallback(
(event: KeyboardEvent<HTMLButtonElement>) => {
if (event.key === "Enter" || event.key === " ") {
Expand All @@ -50,15 +55,15 @@ export const SkipLink: FunctionComponent<ISkipLink> = ({ target, text, as }) =>
role="link"
type="button"
onKeyUp={onKeyUp}
className="fdz-css-skip-links__item"
className={CSS_CLASS}
data-testid="fdz-js-skip-link"
>
{text}
</button>
);
}
return (
<a href={target} className="fdz-css-skip-links__item" data-testid="fdz-js-skip-link">
<a href={target} className={CSS_CLASS} data-testid="fdz-js-skip-link">
{text}
</a>
);
Expand Down
36 changes: 0 additions & 36 deletions src/components/skip-links/styles.css

This file was deleted.

1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @since 1.0.0
*/
declare module "*.css";
declare module "*.module.scss";

declare interface Navigator extends NavigatorUA {}
declare interface WorkerNavigator extends NavigatorUA {}
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export default defineConfig({
}),
react(),
],
css: {
modules: {
generateScopedName: "fdz-css-[hash:base64:8]",
},
},
build: {
minify: true,
lib: {
Expand Down

0 comments on commit 403280c

Please sign in to comment.