forked from danskernesdigitalebibliotek/dpl-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc03903
commit 2354e17
Showing
4 changed files
with
105 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
import { withDesign } from "storybook-addon-designs"; | ||
|
||
import { Input } from "./Input"; | ||
|
||
export default { | ||
title: "Library / Forms / Input", | ||
component: Input, | ||
decorators: [withDesign], | ||
argTypes: { | ||
label: { | ||
defaultValue: "Navn", | ||
}, | ||
type: { | ||
defaultValue: "text", | ||
}, | ||
id: { | ||
defaultValue: "id", | ||
}, | ||
description: { defaultValue: "Dit fulde navn" }, | ||
validation: { defaultValue: "Fejlbesked lorem ipsum dolor" }, | ||
}, | ||
parameters: { | ||
design: { | ||
type: "figma", | ||
url: | ||
"https://www.figma.com/file/xouARmJCONbzbZhpD8XpcM/Brugerprofil?node-id=1239%3A66174", | ||
}, | ||
layout: "fullscreen", | ||
}, | ||
} as ComponentMeta<typeof Input>; | ||
|
||
const Template: ComponentStory<typeof Input> = (args) => <Input {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
|
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export type InputProps = { | ||
label: string; | ||
type: "text" | "password"; | ||
id: string; | ||
description: string; | ||
validation: string; | ||
}; | ||
|
||
export const Input = (props: InputProps) => { | ||
const { label, type, id, description, validation } = props; | ||
|
||
return ( | ||
<div className="dpl-input"> | ||
<label htmlFor={id}>{label}</label> | ||
<input | ||
aria-invalid={validation ? true : false} | ||
aria-describedby={`description-${id}`} | ||
aria-labelledBy={validation ? `validation-${id}` : ""} | ||
id={id} | ||
type={type} | ||
/> | ||
{description && ( | ||
<div className="dpl-input__description" id={`description-${id}`}> | ||
{description} | ||
</div> | ||
)} | ||
{validation && ( | ||
<div id={`validation-${id}`} className="dpl-input__validation"> | ||
{validation} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.dpl-input { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
label { | ||
@extend .text-body-medium-medium; | ||
color: $c-text-secondary-gray; | ||
} | ||
|
||
input { | ||
background-color: transparent; | ||
border: none; | ||
border-bottom: 1px solid $c-global-tertiary-1; | ||
height: 40px; | ||
|
||
&:focus { | ||
border-bottom-color: #000; | ||
outline: none; | ||
} | ||
} | ||
|
||
&__description { | ||
color: $c-text-secondary-gray; | ||
@extend .text-body-small-regular; | ||
@extend .mt-8; | ||
} | ||
|
||
&__validation { | ||
color: $c-signal-alert; | ||
@extend .text-body-small-regular; | ||
@extend .mt-8; | ||
} | ||
} |