Skip to content

Commit

Permalink
feat: #textarea as a component (#189)
Browse files Browse the repository at this point in the history
* add first reused styled version of textarea

* add first reused styled version of textarea

* make #textarea placeholder and label positioning work

* make #textarea placeholder looking good and give them a line-clamp

* enhance #textarea tests and examples + screenshot tests

* add align prop to #textara + correct border radios

* add change log info about the new #textarea + #radio and #checkbox

* add on_change event to #textarea demo examples

* change the order of #textarea in the components listing

* enhance #textarea docs
  • Loading branch information
tujoworker authored May 31, 2019
1 parent 67ea201 commit 5d352ee
Show file tree
Hide file tree
Showing 44 changed files with 1,769 additions and 184 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## May, 27. 2019

- New component in the `dnb-ui-lib`: [Textarea](/uilib/components/textarea). Got also a wider corner radius by `16px (1rem)`.

## May, 27. 2019

- New component in the `dnb-ui-lib`: [Checkbox](/uilib/components/checkbox) and [Radio](/uilib/components/radio) button

## May, 19. 2019

- New component in the `dnb-ui-lib`: Circular [ProgressIndicator](/uilib/components/progress-indicator) bar (spinner with animation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ The `Switch` component (toggle) is a digital on/off switch. Toggle switches are
## [Tabs](/uilib/components/tabs)

Tabs are a set of buttons which allow navigation between content that is related and on the same level of hierarchy.

## [Textarea](/uilib/components/textarea)

The `Textarea` component has to be used as a multi-line text input control with an unlimited number of characters possible.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Example extends PureComponent {
/>
`}
</ComponentBox>
<ComponentBox caption="Show FormStatus (Error)">
<ComponentBox caption="Show failure status">
{/* @jsx */ `
<Input
label="Show status:"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: 'Textarea'
draft: false
status: null
order: 17
---

import Tabs from 'Tags/Tabs'

import TextareaInfo from 'Pages/uilib/components/textarea/textarea-info'
import TextareaProperties from 'Pages/uilib/components/textarea/textarea-properties'
import TextareaEvents from 'Pages/uilib/components/textarea/textarea-events'

# Textarea

<Tabs>
<Tabs.Content>
<TextareaInfo />
</Tabs.Content>
<Tabs.Content>
<TextareaProperties />
</Tabs.Content>
<Tabs.Content>
<TextareaEvents />
</Tabs.Content>
</Tabs>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* UI lib Component Example
*
*/

import React, { PureComponent, Fragment } from 'react'
import ComponentBox from '../../../../shared/tags/ComponentBox'
import styled from '@emotion/styled'

class Example extends PureComponent {
render() {
return (
<Fragment>
<ComponentBox
caption="Placeholder text"
data-dnb-test="textarea-default"
>
{/* @jsx */ `
<Textarea
label="Default:"
rows="2"
cols="20"
value="Textarea value\\nNewline"
on_change={({ value }) => { console.log('on_change', value) }}
on_focus={() => { console.log('on_focus') }}
on_blur={() => { console.log('on_blur') }}
/>
`}
</ComponentBox>
<ComponentBox caption="Placeholder text">
{/* @jsx */ `
<FormLabel for_id="text-textarea-1" text="Placeholder:" />
<Textarea
id="text-textarea-1"
placeholder="Placeholder text"
/>
`}
</ComponentBox>
<ComponentBox caption="Vertical placed label, using `.dnb-form-group`">
{/* @jsx */ `
<Textarea
label="Vertical:"
rows="3"
cols="33"
value="Textarea value with more than 3 lines\\nNewline\\nNewline\\nNewline\\nNewline"
/>
`}
</ComponentBox>
<ComponentBox caption="Horizontal placed label, using `.dnb-form-group`">
{/* @jsx */ `
<Textarea
label="Horizontal:"
rows="3"
value="Nec litora inceptos vestibulum id interdum donec gravida."
/>
`}
</ComponentBox>
<ComponentBox caption="Max length usage">
{/* @jsx */ `
<Textarea
label="Length limit:"
rows="3"
cols="33"
maxLength="20"
required
value="Nec litora inceptos vestibulum id interdum donec gravida."
/>
`}
</ComponentBox>
<ComponentBox
caption="With FormStatus failure message"
data-dnb-test="textarea-error"
>
{/* @jsx */ `
<Textarea
label="Error Message:"
cols="33"
value="Nec litora inceptos vestibulum id interdum donec gravida."
status="Message to the user"
/>
`}
</ComponentBox>
<ComponentBox caption="Show failure status">
{/* @jsx */ `
<Textarea
label="Show status:"
status="error"
value="Shows status with border only"
/>
`}
</ComponentBox>
<ComponentBox caption="Disabled textarea">
{/* @jsx */ `
<Textarea
label="Disabled:"
disabled
value="Nec litora inceptos vestibulum id interdum donec gravida."
/>
`}
</ComponentBox>
</Fragment>
)
}
}

const Wrapper = styled.div`
display: block;
width: 100%;
${'' /* .dnb-textarea textarea {
min-width: 10rem;
}
.dnb-form-label + .dnb-textarea {
margin-top: 0;
} */}
`

export { Example }
export default () => (
<Wrapper>
<Example />
</Wrapper>
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
---
title: 'Textarea'
draft: false
draft: true
---

import CodeBlock from 'Tags/CodeBlock'
import ComponentBox from 'Tags/ComponentBox'

## Textarea

<CodeBlock reactLive hideCode caption="Default Textarea">
{`
<div className="dnb-form-group dnb-form-group__position--vertical" data-dnb-test="textarea-default" >
<label htmlFor="textarea-default">
<div className="dnb-form-group dnb-form-group__position--vertical" >
<label className="dnb-label" htmlFor="textarea-default">
Label:
</label>
<textarea id="textarea-default" className="dnb-textarea" rows="2" cols="20" defaultValue="Nec litora inceptos vestibulum id interdum donec gravida nostra lacinia bibendum hendrerit porttitor volutpat nam duis nisl scelerisque sapien erat" />
Expand All @@ -22,7 +19,7 @@ import ComponentBox from 'Tags/ComponentBox'
<CodeBlock reactLive hideCode caption="Disabled Textarea">
{`
<div className="dnb-form-group">
<label htmlFor="vestibulum">
<label className="dnb-label" htmlFor="vestibulum">
Label:
</label>
<textarea id="vestibulum" className="dnb-textarea" rows="5" cols="33" disabled defaultValue="Nec litora inceptos vestibulum id interdum donec gravida nostra lacinia bibendum hendrerit porttitor volutpat nam duis nisl scelerisque sapien erat" />
Expand All @@ -33,7 +30,7 @@ import ComponentBox from 'Tags/ComponentBox'
<ComponentBox hideCode caption="Textarea with status message">
{`
<div className="dnb-form-group dnb-form-group__position--vertical">
<label htmlFor="vestibulum">
<label className="dnb-label" htmlFor="vestibulum">
Label:
</label>
<textarea id="vestibulum" className="dnb-textarea status--error" rows="5" cols="33" defaultValue="Nec litora inceptos vestibulum id interdum donec gravida nostra lacinia bibendum hendrerit porttitor volutpat nam duis nisl scelerisque sapien erat" />
Expand All @@ -44,14 +41,12 @@ import ComponentBox from 'Tags/ComponentBox'
<ComponentBox hideCode>
{`
<div className="dnb-form-group">
<label htmlFor="gravida">
<div className="dnb-form-group dnb-form-group__position--vertical" >
<label className="dnb-label" htmlFor="gravida">
Label:
</label>
<div className="dnb-form-group dnb-form-group__position--vertical" >
<textarea id="gravida" className="dnb-textarea" rows="3" cols="33" defaultValue="Nec litora inceptos vestibulum id interdum donec gravida nostra lacinia bibendum hendrerit porttitor volutpat nam duis nisl scelerisque sapien erat" />
<FormStatus status="info" text="Message to the user" />
</div>
<textarea id="gravida" className="dnb-textarea" rows="3" cols="33" defaultValue="Nec litora inceptos vestibulum id interdum donec gravida nostra lacinia bibendum hendrerit porttitor volutpat nam duis nisl scelerisque sapien erat" />
<FormStatus status="info" text="Message to the user" />
</div>
`}
</ComponentBox>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
draft: true
---

| Events | Description |
| ----------- | -------------------------------------------------------------------------------------------- |
| `on_change` | _(optional)_ will be called on value changes made by the user. Returns a string `{ value }`. |
| `on_focus` | _(optional)_ will be called on focus set by the user. Returns a string `{ value }`. |
| `on_blur` | _(optional)_ will be called on blur set by the user. Returns a string `{ value }`. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
draft: true
---

import Examples from 'Pages/uilib/components/textarea/Examples'
import TextareaAsElement from 'Pages/uilib/components/textarea/textarea-element'

## Description

The `Textarea` component has to be used as a multi-line text input control with an unlimited number of characters possible.

## Demos

<Examples />

### Textarea as HTML element only

<TextareaAsElement />
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
draft: true
---

| Properties | Description |
| ---------------- | -------------------------------------------------------------------------------------------------------------- |
| `id` | _(optional)_ the `id` attribute of the textarea element |
| `value` | _(optional)_ the content value of the textarea. |
| `align` | _(optional)_ defines the `text-align` of the textarea. Defaults to `left`. |
| `placeholder` | _(optional)_ the placeholder which shows up once the textarea value is empty |
| `label` | _(optional)_ prepends the Form Label component. If no ID is provided, a random ID is created. textarea. |
| `status` | _(optional)_ text with a status message. The style defaults to an error message. |
| `status_state` | _(optional)_ defines the state of the status. Currently are two statuses `[error, info]`. Defaults to `error`. |
| `textarea_state` | _(optional)_ to control the visual focus state as a prop, like `focus` or `blur`. |
| `textarea_class` | _(optional)_ in case we have to set a custom textarea class. |
| `disabled` | _(optional)_ to disable the textarea. |
4 changes: 0 additions & 4 deletions packages/dnb-design-system-portal/src/pages/uilib/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ order: 6
import CodeBlock from 'Tags/CodeBlock'
import ComponentBox from 'Tags/ComponentBox'
import { Link } from 'dnb-ui-lib/src/elements'

import OtherElements from 'Pages/uilib/elements/other'
import Anchor from 'Pages/uilib/elements/anchor'
import Blockquote from 'Pages/uilib/elements/blockquote'
import Textarea from 'Pages/uilib/elements/textarea'
import Tables from 'Pages/uilib/elements/tables'
import Lists from 'Pages/uilib/elements/lists'
import Code from 'Pages/uilib/elements/code'
Expand Down Expand Up @@ -71,7 +69,6 @@ render(<StyledLink href="/" target="_blank">Styled Link</StyledLink>)
- [Blockquote](#blockquote)
- [Lists](#lists)
- [Tables](#tables)
- [Textarea](#textarea)
- [Select](#missing-html-elements)
- [Radio](#missing-html-elements)
- [Checkbox](#missing-html-elements)
Expand All @@ -81,7 +78,6 @@ render(<StyledLink href="/" target="_blank">Styled Link</StyledLink>)
<Blockquote />
<Lists />
<Tables />
<Textarea />

---

Expand Down
14 changes: 14 additions & 0 deletions packages/dnb-ui-lib/src/components/Textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* ATTENTION: This file is auto generated by using "prepareTemplates".
* Do not change the content!
*
*/

/**
* Library Index textarea to autogenerate all the components and patterns
* Used by "prepareTextareas"
*/

import Textarea from './textarea/Textarea'
export * from './textarea/Textarea'
export default Textarea
4 changes: 3 additions & 1 deletion packages/dnb-ui-lib/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Slider from './slider/Slider'
import StepIndicator from './step-indicator/StepIndicator'
import Switch from './switch/Switch'
import Tabs from './tabs/Tabs'
import Textarea from './textarea/Textarea'

// define / export all the aviable components
export {
Expand All @@ -52,5 +53,6 @@ export {
Slider,
StepIndicator,
Switch,
Tabs
Tabs,
Textarea
}
7 changes: 5 additions & 2 deletions packages/dnb-ui-lib/src/components/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Slider from './slider/Slider'
import StepIndicator from './step-indicator/StepIndicator'
import Switch from './switch/Switch'
import Tabs from './tabs/Tabs'
import Textarea from './textarea/Textarea'

// define / export all the aviable components
export {
Expand All @@ -54,7 +55,8 @@ export {
Slider,
StepIndicator,
Switch,
Tabs
Tabs,
Textarea
}

export const getComponents = () => {
Expand All @@ -78,7 +80,8 @@ export const getComponents = () => {
Slider,
StepIndicator,
Switch,
Tabs
Tabs,
Textarea
}
}

Expand Down
Loading

0 comments on commit 5d352ee

Please sign in to comment.