Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into fix/2042-Character-counter-inital…
Browse files Browse the repository at this point in the history
…-value
  • Loading branch information
paal2707 committed May 22, 2024
2 parents 815cb5b + 1c549b7 commit 22ac444
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/css/native-select.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
background-image: none;
}

.fds-native-select--small {
.fds-native-select--sm {
padding: 0 var(--fds-spacing-2);
padding-right: var(--fds-spacing-8);
height: var(--fds-sizing-10);
}

.fds-native-select--medium {
.fds-native-select--md {
padding: 0 var(--fds-spacing-3);
padding-right: var(--fds-spacing-10);
height: var(--fds-sizing-12);
}

.fds-native-select--large {
.fds-native-select--lg {
padding: 0 var(--fds-spacing-4);
padding-right: var(--fds-spacing-12);
height: var(--fds-sizing-14);
Expand Down
12 changes: 6 additions & 6 deletions packages/css/pagination.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
visibility: hidden;
}

.fds-pagination--small {
.fds-pagination--sm {
--fds-pagination-chevron-margin: var(--fds-spacing-2);
}

.fds-pagination--medium {
.fds-pagination--md {
--fds-pagination-chevron-margin: var(--fds-spacing-2);
}

.fds-pagination--large {
.fds-pagination--lg {
--fds-pagination-chevron-margin: var(--fds-spacing-2);
}

Expand All @@ -41,17 +41,17 @@
margin-right: var(--fds-pagination-listitem-margin);
}

.fds-pagination--small .fds-pagination__item {
.fds-pagination--sm .fds-pagination__item {
--fds-pagination-listitem-margin: var(--fds-spacing-2);
--fds-pagination-ellipsis-width: var(--fds-sizing-10);
}

.fds-pagination--medium .fds-pagination__item {
.fds-pagination--md .fds-pagination__item {
--fds-pagination-listitem-margin: var(--fds-spacing-4);
--fds-pagination-ellipsis-width: var(--fds-sizing-12);
}

.fds-pagination--large .fds-pagination__item {
.fds-pagination--lg .fds-pagination__item {
--fds-pagination-listitem-margin: var(--fds-spacing-6);
--fds-pagination-ellipsis-width: var(--fds-sizing-14);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/css/radio.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,19 @@

/** Sizing */

.fds-radio--small {
.fds-radio--sm {
--fds-radio-size: var(--fds-sizing-5);

min-height: var(--fds-sizing-10);
}

.fds-radio--medium {
.fds-radio--md {
--fds-radio-size: var(--fds-sizing-6);

min-height: var(--fds-sizing-11);
}

.fds-radio--large {
.fds-radio--lg {
--fds-radio-size: var(--fds-sizing-7);

min-height: var(--fds-sizing-12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Preview: StoryFn<typeof Pagination> = (args) => {
};

Preview.args = {
size: 'medium',
size: 'md',
nextLabel: 'Neste',
previousLabel: 'Forrige',
totalPages: 10,
Expand Down
21 changes: 15 additions & 6 deletions packages/react/src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type * as React from 'react';
import cl from 'clsx/lite';
import { ChevronLeftIcon, ChevronRightIcon } from '@navikt/aksel-icons';

import { getSize } from '../../utilities/getSize';

import { PaginationRoot } from './PaginationRoot';
import { PaginationContent } from './PaginationContent';
import { PaginationItem } from './PaginationItem';
Expand All @@ -11,13 +13,18 @@ import { PaginationEllipsis } from './PaginationEllipsis';
import { PaginationNext, PaginationPrevious } from './PaginationNextPrev';
import { usePagination } from './usePagination';

type OldPaginationSizes = 'small' | 'medium' | 'large';

export type PaginationProps = {
/** Sets the text label for the next page button */
nextLabel: string;
/** Sets the text label for the previous page button */
previousLabel: string;
/** Sets the size of the component */
size?: 'small' | 'medium' | 'large';
/** Sets the size of the component
* @default md
* @note `small`, `medium`, `large` is deprecated
*/
size?: 'sm' | 'md' | 'lg' | OldPaginationSizes;
/** Sets how compact the component will be. If true, only 5 steps will show. */
compact?: boolean;
/** Hides the component's previous and next button labels */
Expand All @@ -35,17 +42,16 @@ export type PaginationProps = {
} & Omit<React.HTMLAttributes<HTMLElement>, 'onChange'>;

const iconSize = {
small: '1rem',
medium: '1.5rem',
large: '2rem',
sm: '1rem',
md: '1.5rem',
lg: '2rem',
};

export const Pagination = forwardRef<HTMLElement, PaginationProps>(
(
{
nextLabel = '',
previousLabel = '',
size = 'medium',
compact = false,
hideLabels = false,
currentPage = 1,
Expand All @@ -61,6 +67,9 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
currentPage,
totalPages,
});

const size = getSize(rest.size || 'md') as 'sm' | 'md' | 'lg';

return (
<PaginationRoot
ref={ref}
Expand Down
16 changes: 12 additions & 4 deletions packages/react/src/components/Pagination/PaginationRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { Slot } from '@radix-ui/react-slot';
import { createContext, forwardRef, type HTMLAttributes } from 'react';

import { getSize } from '../../utilities/getSize';

import type { PaginationProps } from './Pagination';

type PaginationContextProps = {
size: NonNullable<PaginationRootProps['size']>;
compact: boolean;
};

export const PaginationContext = createContext<PaginationContextProps>({
size: 'medium',
size: 'md',
compact: false,
});

export type PaginationRootProps = {
/**
* Sets the size of the component
* @default medium
* @default md
* @note `small`, `medium`, `large` is deprecated
*/
size?: 'small' | 'medium' | 'large';
size?: PaginationProps['size'];
/**
* Sets how compact the component will be. If true, only 5 steps will show.
* @default false
Expand All @@ -30,8 +35,11 @@ export type PaginationRootProps = {
} & HTMLAttributes<HTMLElement>;

export const PaginationRoot = forwardRef<HTMLElement, PaginationRootProps>(
({ asChild, size = 'medium', compact = false, ...rest }, ref) => {
({ asChild, compact = false, ...rest }, ref) => {
const Component = asChild ? Slot : 'nav';
const size = getSize(rest.size || 'md') as NonNullable<
PaginationRootProps['size']
>;

return (
<PaginationContext.Provider value={{ size, compact }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Preview: StoryFn<typeof NativeSelect> = (args) => (

Preview.args = {
label: 'Velg et fjell',
size: 'medium',
size: 'md',
disabled: false,
readOnly: false,
};
Expand Down
11 changes: 7 additions & 4 deletions packages/react/src/components/form/NativeSelect/NativeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ErrorMessage, Label, Paragraph } from '../../Typography';

import { useNativeSelect } from './useNativeSelect';

type OldNativeSelectSizes = 'small' | 'medium' | 'large';

export type NativeSelectProps = {
/**
* Label that appears over the select box. */
Expand All @@ -25,9 +27,10 @@ export type NativeSelectProps = {
multiple?: boolean;
/**
* Defines the size of the select.
* @default medium
* */
size?: 'small' | 'medium' | 'large';
* @default md
* @note `small`, `medium`, `large` is deprecated
**/
size?: 'sm' | 'md' | 'lg' | OldNativeSelectSizes;
/** Error message for form field */
error?: ReactNode;
/** Defines if the select is readOnly
Expand Down Expand Up @@ -59,7 +62,7 @@ export const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>(
descriptionId,
errorId,
readOnly = false,
size = 'medium',
size = 'md',
} = useNativeSelect(props);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useContext } from 'react';
import type { FormField } from '../useFormField';
import { useFormField } from '../useFormField';
import { FieldsetContext } from '../Fieldset/FieldsetContext';
import { getSize } from '../../../utilities/getSize';

import type { NativeSelectProps } from './NativeSelect';

Expand All @@ -26,10 +27,14 @@ export const useNativeSelect: UseNativeSelect = (props) => {
...rest
} = useFormField(props, 'select');

const size = getSize(fieldset?.size ?? props.size ?? 'md') as NonNullable<
NativeSelectProps['size']
>;

return {
...rest,
readOnly,
size: fieldset?.size ?? props.size,
size,
selectProps: {
...selectProps,
readOnly,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/form/Radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Preview: Story = {
disabled: false,
readOnly: false,
value: 'value',
size: 'medium',
size: 'md',
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/form/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
inputProps,
descriptionId,
hasError,
size = 'medium',
size = 'md',
readOnly,
} = useRadio(props);

Expand Down

0 comments on commit 22ac444

Please sign in to comment.