-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move icon next to label in
StudioIconTextfield
(#14469)
- Loading branch information
Showing
11 changed files
with
193 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 16 additions & 8 deletions
24
.../libs/studio-components/src/components/StudioIconTextfield/StudioIconTextfield.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 46 additions & 8 deletions
54
...libs/studio-components/src/components/StudioIconTextfield/StudioIconTextfield.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,63 @@ | ||
import React from 'react'; | ||
import type { Meta, StoryFn } from '@storybook/react'; | ||
import { PencilIcon } from '@studio/icons'; | ||
import { KeyVerticalIcon } from '@studio/icons'; | ||
import { StudioIconTextfield } from './StudioIconTextfield'; | ||
|
||
type Story = StoryFn<typeof StudioIconTextfield>; | ||
|
||
const meta: Meta = { | ||
title: 'Components/StudioIconTextfield', | ||
component: StudioIconTextfield, | ||
argTypes: { | ||
value: { | ||
control: 'text', | ||
parameters: { | ||
docs: { | ||
canvas: { | ||
height: '100%', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
export const Preview: Story = (args) => <StudioIconTextfield {...args}></StudioIconTextfield>; | ||
export const WithIcon: Story = (args) => <StudioIconTextfield {...args} />; | ||
WithIcon.args = { | ||
icon: <KeyVerticalIcon />, | ||
label: 'A label', | ||
value: 'A value', | ||
}; | ||
|
||
export const WithoutIcon: Story = (args) => <StudioIconTextfield {...args} />; | ||
WithoutIcon.args = { | ||
label: 'A label', | ||
value: 'A value', | ||
}; | ||
|
||
Preview.args = { | ||
icon: <PencilIcon />, | ||
value: 2.3, | ||
export const WithErrorMessage: Story = (args) => <StudioIconTextfield {...args} />; | ||
WithErrorMessage.args = { | ||
label: 'A label', | ||
value: 'A faulty value', | ||
error: 'Your custom error message!', | ||
}; | ||
|
||
export const AsReadOnly: Story = (args) => <StudioIconTextfield {...args} />; | ||
AsReadOnly.args = { | ||
label: 'A label', | ||
value: 'A readonly value', | ||
readOnly: true, | ||
}; | ||
|
||
export const AsReadOnlyWithIcon: Story = (args) => <StudioIconTextfield {...args} />; | ||
AsReadOnlyWithIcon.args = { | ||
icon: <KeyVerticalIcon />, | ||
label: 'A label', | ||
value: 'A readonly value', | ||
readOnly: true, | ||
}; | ||
|
||
export const AsReadOnlyWithIconAndDescription: Story = (args) => <StudioIconTextfield {...args} />; | ||
AsReadOnlyWithIconAndDescription.args = { | ||
icon: <KeyVerticalIcon />, | ||
description: 'A description', | ||
label: 'A label', | ||
value: 'A readonly value', | ||
readOnly: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 41 additions & 10 deletions
51
frontend/libs/studio-components/src/components/StudioIconTextfield/StudioIconTextfield.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,59 @@ | ||
import React, { forwardRef } from 'react'; | ||
import React, { forwardRef, useId } from 'react'; | ||
import { StudioTextfield, type StudioTextfieldProps } from '../StudioTextfield'; | ||
import cn from 'classnames'; | ||
|
||
import classes from './StudioIconTextfield.module.css'; | ||
import type { Override } from '../../types/Override'; | ||
import { Label } from '@digdir/designsystemet-react'; | ||
import { PadlockLockedFillIcon } from '@studio/icons'; | ||
|
||
export type StudioIconTextfieldProps = { | ||
icon: React.ReactNode; | ||
} & StudioTextfieldProps; | ||
export type StudioIconTextfieldProps = Override< | ||
{ | ||
icon?: React.ReactNode; | ||
label: string; | ||
}, | ||
StudioTextfieldProps | ||
>; | ||
|
||
export const StudioIconTextfield = forwardRef<HTMLDivElement, StudioIconTextfieldProps>( | ||
( | ||
{ icon, className: givenClassName, ...rest }: StudioIconTextfieldProps, | ||
{ icon, id, label, className: givenClassName, readOnly, ...rest }: StudioIconTextfieldProps, | ||
ref, | ||
): React.ReactElement => { | ||
const generatedId = useId(); | ||
const textFieldId = id ?? generatedId; | ||
const className = cn(givenClassName, classes.container); | ||
return ( | ||
<div className={className} ref={ref}> | ||
<div aria-hidden className={classes.prefixIcon}> | ||
{icon} | ||
</div> | ||
<StudioTextfield {...rest} className={classes.textfield} /> | ||
<IconLabel htmlFor={textFieldId} icon={icon} label={label} readonly={readOnly} /> | ||
<StudioTextfield | ||
disabled={readOnly} | ||
id={textFieldId} | ||
size='sm' | ||
className={classes.textfield} | ||
{...rest} | ||
/> | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
type IconLabelProps = { | ||
htmlFor: string; | ||
icon?: React.ReactNode; | ||
label: string; | ||
readonly?: boolean; | ||
}; | ||
|
||
const IconLabel = ({ htmlFor, icon, label, readonly }: IconLabelProps): React.ReactElement => { | ||
return ( | ||
<div className={classes.iconLabel}> | ||
{icon} | ||
<Label size='sm' htmlFor={htmlFor}> | ||
{label} | ||
</Label> | ||
{readonly && <PadlockLockedFillIcon className={classes.padLockIcon} />} | ||
</div> | ||
); | ||
}; | ||
|
||
StudioIconTextfield.displayName = 'StudioIconTextfield'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
frontend/packages/ux-editor/src/components/Properties/PageConfigPanel/EditPageId.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
.changePageId { | ||
background-color: var(--fds-semantic-surface-neutral-default); | ||
} | ||
|
||
.idInput { | ||
padding: var(--fds-spacing-5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters