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

refactor(css): Create utils.css #1811

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/css/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@charset "UTF-8";

@import url('./react-css-modules.css');
@import url('./utils.css');
@import url('./alert.css');
27 changes: 0 additions & 27 deletions packages/css/react-css-modules.css
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
@layer fds.utilities {
/**
* Visually hide an element, but leave it available for screen readers
*/
.fds-utility-visuallyHidden-1ed11112 {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
overflow: hidden;
padding: 0;
position: absolute;
white-space: nowrap;
width: 1px;
}

/**
* Apply a focus outline on an element when it is focused with keyboard
*/
.fds-utility-focusable-1ed11112:focus-visible {
--fds-focus-border-width: 3px;

outline: var(--fds-focus-border-width) solid var(--fds-semantic-border-focus-outline);
outline-offset: var(--fds-focus-border-width);
box-shadow: 0 0 0 var(--fds-focus-border-width) var(--fds-semantic-border-focus-boxshadow);
}
}

@layer fds.button {
.fds-button-button-8fa00f0f {
--fc-button-padding: 0 var(--fds-spacing-4);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@layer fds.utilities {
@layer fds.utils {
/**
* Visually hide an element, but leave it available for screen readers
*/
.visuallyHidden {
.fds-sr-only {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
Expand All @@ -16,11 +16,13 @@
/**
* Apply a focus outline on an element when it is focused with keyboard
*/
.focusable:focus-visible {
.fds-focus:focus-visible {
--fds-focus-border-width: 3px;

outline: var(--fds-focus-border-width) solid var(--fds-semantic-border-focus-outline);
outline: var(--fds-focus-border-width) solid
var(--fds-semantic-border-focus-outline);
outline-offset: var(--fds-focus-border-width);
box-shadow: 0 0 0 var(--fds-focus-border-width) var(--fds-semantic-border-focus-boxshadow);
box-shadow: 0 0 0 var(--fds-focus-border-width)
var(--fds-semantic-border-focus-boxshadow);
}
}
2 changes: 1 addition & 1 deletion packages/react/scripts/generate-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fs.ensureDirSync(outputFolder);

/** To exclude files when we start writing css manually */
const ignore = [''];
const additional = ['utility.module.css'];
const additional = [''];

const findComponentName = (filePath: string) => {
let fileName = filePath.split('/src/')[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { forwardRef, useContext } from 'react';

import { Paragraph, Heading } from '../..';
import classes from '../Accordion.module.css';
import utilityClasses from '../../../utilities/utility.module.css';
import { AccordionItemContext } from '../AccordionItem';

export type AccordionHeaderProps = {
Expand Down Expand Up @@ -45,7 +44,7 @@ export const AccordionHeader = forwardRef<
>
<button
type='button'
className={cl(classes.accordionButton, utilityClasses.focusable)}
className={cl(classes.accordionButton, `fds-focus`)}
onClick={handleClick}
aria-expanded={context.open}
aria-controls={context.contentId}
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { ButtonHTMLAttributes } from 'react';
import cl from 'clsx';
import { Slot } from '@radix-ui/react-slot';

import utilityClasses from '../../utilities/utility.module.css';
import type { OverridableComponent } from '../../types/OverridableComponent';

import classes from './Button.module.css';
Expand Down Expand Up @@ -57,7 +56,7 @@ export const Button: OverridableComponent<ButtonProps, HTMLButtonElement> =
type={type}
className={cl(
classes.button,
utilityClasses.focusable,
`fds-focus`,
classes[size],
classes[variant],
classes[color],
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cl from 'clsx';
import { Slot } from '@radix-ui/react-slot';

import type { OverridableComponent } from '../../types/OverridableComponent';
import utilityClasses from '../../utilities/utility.module.css';

import classes from './Card.module.css';

Expand Down Expand Up @@ -54,7 +53,7 @@ export const Card: OverridableComponent<CardProps, HTMLDivElement> = forwardRef(
classes.card,
classes[color],
isLink && classes.linkCard,
isLink && utilityClasses.focusable,
isLink && `fds-focus`,
className,
)}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { XMarkIcon } from '@navikt/aksel-icons';
import classes from '../Chip.module.css';
import { Paragraph } from '../../Typography';
import { ChipGroupContext } from '../Group/Group';
import utilityClasses from '../../../utilities/utility.module.css';

export type RemovableChipProps = {
/**
Expand All @@ -26,7 +25,7 @@ export const RemovableChip = forwardRef<HTMLButtonElement, RemovableChipProps>(
ref={ref}
className={cl(
classes.chipButton,
utilityClasses.focusable,
`fds-focus`,
classes[group?.size || size],
classes.removable,
className,
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/components/Chip/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cl from 'clsx';

import { Paragraph } from '../../Typography';
import { ChipGroupContext } from '../Group/Group';
import utilityClasses from '../../../utilities/utility.module.css';
import classes from '../Chip.module.css';

export type ToggleChipProps = {
Expand Down Expand Up @@ -46,7 +45,7 @@ export const ToggleChip = forwardRef<HTMLButtonElement, ToggleChipProps>(
aria-pressed={selected}
className={cl(
classes.chipButton,
utilityClasses.focusable,
`fds-focus`,
classes[group?.size || size],
{ [classes.spacing]: shouldDisplayCheckmark },
className,
Expand Down
9 changes: 2 additions & 7 deletions packages/react/src/components/HelpText/HelpText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cl from 'clsx';
import type { Placement } from '@floating-ui/utils';

import { Popover } from '../Popover';
import utilClasses from '../../utilities/utility.module.css';
import type { PopoverProps } from '../Popover/Popover';
import type { PortalProps } from '../../types/Portal';

Expand Down Expand Up @@ -55,11 +54,7 @@ const HelpText = ({
variant='tertiary'
>
<button
className={cl(
classes.helpTextButton,
utilClasses.focusable,
className,
)}
className={cl(classes.helpTextButton, `fds-focus`, className)}
aria-expanded={open}
onClick={() => setOpen(!open)}
{...rest}
Expand All @@ -78,7 +73,7 @@ const HelpText = ({
className={cl(classes.helpTextIcon, classes[size], className)}
openState={open}
/>
<span className={utilClasses.visuallyHidden}>{title}</span>
<span className={`fds-sr-only`}>{title}</span>
</button>
</Popover.Trigger>
<Popover.Content className={classes.helpTextContent}>
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/components/SkipLink/SkipLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AnchorHTMLAttributes, ReactNode } from 'react';
import cl from 'clsx';

import utilityClasses from './../../utilities/utility.module.css';
import classes from './SkipLink.module.css';

export type SkipLinkProps = {
Expand All @@ -21,7 +20,7 @@ export const SkipLink = ({
return (
<a
href={href}
className={cl(utilityClasses.visuallyHidden, classes.skiplink, className)}
className={cl(`fds-sr-only`, classes.skiplink, className)}
{...rest}
>
{children}
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/components/Table/TableHeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { AriaAttributes } from 'react';
import * as React from 'react';
import cl from 'clsx';

import utilityClasses from '../../utilities/utility.module.css';

import classes from './Table.module.css';

const SORT_ICON = {
Expand Down Expand Up @@ -63,7 +61,7 @@ export const TableHeaderCell = React.forwardRef<
>
{sortable && (
<button
className={utilityClasses.focusable}
className={`fds-focus`}
onClick={onSortClick}
>
{children}
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/components/form/CharacterCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import utilityClasses from '../../utilities/utility.module.css';
import { ErrorMessage } from '../Typography';

export type CharacterLimitProps = Omit<
Expand Down Expand Up @@ -42,7 +41,7 @@ export const CharacterCounter = ({
return (
<>
<span
className={utilityClasses.visuallyHidden}
className={`fds-sr-only`}
id={id}
>
{srLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cl from 'clsx';

import { ComboboxContext } from '../Combobox';
import classes from '../Combobox.module.css';
import utilityClasses from '../../../../utilities/utility.module.css';

export const ComboboxClearButton = () => {
const context = useContext(ComboboxContext);
Expand All @@ -26,11 +25,7 @@ export const ComboboxClearButton = () => {
return (
<button
disabled={disabled}
className={cl(
classes.clearButton,
classes[size],
utilityClasses.focusable,
)}
className={cl(classes.clearButton, classes[size], `fds-focus`)}
onClick={() => {
if (readOnly) return;
if (disabled) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Label, Paragraph } from '../../../Typography';
import type { ComboboxProps } from '../Combobox';
import type { useFormField } from '../../useFormField';
import classes from '../Combobox.module.css';
import utilityClasses from '../../../../utilities/utility.module.css';

type ComboboxLabelProps = {
label?: ComboboxProps['label'];
Expand All @@ -30,10 +29,7 @@ export const ComboboxLabel = ({
<Label
size={size}
htmlFor={formFieldProps.inputProps.id}
className={cl(
classes.label,
hideLabel && utilityClasses.visuallyHidden,
)}
className={cl(classes.label, hideLabel && `fds-sr-only`)}
>
{readOnly && (
<PadlockLockedFillIcon
Expand All @@ -51,10 +47,7 @@ export const ComboboxLabel = ({
>
<div
id={formFieldProps.descriptionId}
className={cl(
classes.description,
hideLabel && utilityClasses.visuallyHidden,
)}
className={cl(classes.description, hideLabel && `fds-sr-only`)}
>
{description}
</div>
Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/components/form/Fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cl from 'clsx';
import { PadlockLockedFillIcon } from '@navikt/aksel-icons';

import { Label, Paragraph, ErrorMessage } from '../../Typography';
import utilityclasses from '../../../utilities/utility.module.css';
import type { FormFieldProps } from '../useFormField';

import { useFieldset } from './useFieldset';
Expand Down Expand Up @@ -75,7 +74,7 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
<span
className={cl(
classes.legendContent,
hideLegend && utilityclasses.visuallyHidden,
hideLegend && `fds-sr-only`,
)}
>
{readOnly && (
Expand All @@ -96,10 +95,7 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
>
<div
id={descriptionId}
className={cl(
classes.description,
hideLegend && utilityclasses.visuallyHidden,
)}
className={cl(classes.description, hideLegend && `fds-sr-only`)}
>
{description}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { omit } from '../../../utilities';
import { ErrorMessage, Label, Paragraph } from '../../Typography';

import classes from './NativeSelect.module.css';
import utilityClasses from './../../../utilities/utility.module.css';
import { useNativeSelect } from './useNativeSelect';

export type NativeSelectProps = {
Expand Down Expand Up @@ -76,10 +75,7 @@ export const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>(
weight='medium'
size={size}
htmlFor={selectProps.id}
className={cl(
classes.label,
hideLabel && utilityClasses.visuallyHidden,
)}
className={cl(classes.label, hideLabel && 'fds-sr-only')}
>
{readOnly && (
<PadlockLockedFillIcon
Expand All @@ -98,7 +94,7 @@ export const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>(
className={cl(
classes.select,
classes[size],
utilityClasses.focusable,
`fds-focus`,
props.multiple && classes.multiple,
className,
)}
Expand Down
14 changes: 4 additions & 10 deletions packages/react/src/components/form/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { FormFieldProps } from '../useFormField';

import { useSearch } from './useSearch';
import classes from './Search.module.css';
import utilityClasses from './../../../utilities/utility.module.css';

export type SearchProps = {
/** Label */
Expand Down Expand Up @@ -122,10 +121,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
size={size}
weight='medium'
htmlFor={inputProps.id}
className={cl(
classes.label,
hideLabel && utilityClasses.visuallyHidden,
)}
className={cl(classes.label, hideLabel && 'fds-sr-only')}
>
<span>{label}</span>
</Label>
Expand All @@ -146,7 +142,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
disabled={disabled}
className={cl(
classes.input,
utilityClasses.focusable,
`fds-focus`,
isSimple && classes.simple,
!isSimple && classes.withSearchButton,
)}
Expand All @@ -156,14 +152,12 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
/>
{showClearButton && (
<button
className={cl(classes.clearButton, utilityClasses.focusable)}
className={cl(classes.clearButton, `fds-focus`)}
type='button'
onClick={handleClear}
disabled={disabled}
>
<span className={utilityClasses.visuallyHidden}>
{clearButtonLabel}
</span>
<span className={`fds-sr-only`}>{clearButtonLabel}</span>
<XMarkIcon aria-hidden />
</button>
)}
Expand Down
Loading
Loading