This repository was archived by the owner on Jun 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +192
-0
lines changed Expand file tree Collapse file tree 6 files changed +192
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { renderToStaticMarkup } from 'react-dom/server' ;
3+ import { Label } from '../src/index' ;
4+
5+ describe ( '<Label />' , ( ) => {
6+ it ( 'renders basic <Label />' , ( ) => {
7+ expect ( renderToStaticMarkup ( < Label /> ) ) . toEqual (
8+ '<label class="pt-label"></label>'
9+ ) ;
10+ } ) ;
11+
12+ it ( 'renders basic <Label /> with props' , ( ) => {
13+ expect ( renderToStaticMarkup ( < Label text = "Label A" inline /> ) ) . toEqual (
14+ '<label class="pt-label pt-inline">Label A</label>'
15+ ) ;
16+ } ) ;
17+
18+ it ( 'renders disabled <Label /> with muted' , ( ) => {
19+ expect (
20+ renderToStaticMarkup ( < Label text = "Label A" disabled muted = "(required)" /> )
21+ ) . toEqual (
22+ '<label class="pt-label pt-disabled">Label A<span class="pt-text-muted">(required)</span></label>'
23+ ) ;
24+ } ) ;
25+
26+ it ( 'renders <Label /> with basic input' , ( ) => {
27+ expect (
28+ renderToStaticMarkup (
29+ < Label text = "Label A" >
30+ < input disabled className = "pt-input" />
31+ </ Label >
32+ )
33+ ) . toEqual (
34+ '<label class="pt-label">Label A<input disabled="" class="pt-input"/></label>'
35+ ) ;
36+ } ) ;
37+ } ) ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+ import classnames from 'classnames' ;
4+
5+ const Label = ( {
6+ children,
7+ className,
8+ disabled,
9+ inline,
10+ text,
11+ muted,
12+ ...rest
13+ } ) => {
14+ return (
15+ < label
16+ className = { classnames (
17+ 'pt-label' ,
18+ { 'pt-disabled' : disabled } ,
19+ { 'pt-inline' : inline } ,
20+ className
21+ ) }
22+ { ...rest }
23+ >
24+ { text }
25+ { muted && < span className = "pt-text-muted" > { muted } </ span > }
26+ { children }
27+ </ label >
28+ ) ;
29+ } ;
30+
31+ /**
32+ * Label property types.
33+ */
34+ Label . propTypes = {
35+ /**
36+ * Primary content.
37+ */
38+ children : PropTypes . node ,
39+
40+ /**
41+ * Additional CSS classes.
42+ */
43+ className : PropTypes . string ,
44+
45+ /**
46+ * Adds appereance of `disabled` style.
47+ */
48+ disabled : PropTypes . bool ,
49+
50+ /**
51+ * Align label and children elements on same line.
52+ */
53+ inline : PropTypes . bool ,
54+
55+ /**
56+ * Text to be displayed in label.
57+ */
58+ text : PropTypes . string ,
59+
60+ /**
61+ * Adds extra information to label.
62+ */
63+ muted : PropTypes . string ,
64+ } ;
65+
66+ /**
67+ * Label default properties.
68+ */
69+ Label . defaultProps = {
70+ children : null ,
71+ className : '' ,
72+ disabled : false ,
73+ inline : false ,
74+ text : '' ,
75+ muted : '' ,
76+ } ;
77+
78+ export default Label ;
Original file line number Diff line number Diff line change 1+ Labels enhance the usability of your forms.
2+
3+ ``` js static
4+ import { Label } from ' blueprint-components' ;
5+ ```
6+
7+ Additionally:
8+
9+ ``` js static
10+ import { InputGroup , Button , Classes } from ' @blueprintjs/core' ;
11+ ```
12+
13+ Simple labels are useful for basic forms for a single ` <input /> ` .
14+
15+ ``` jsx
16+ < div className= " " >
17+ < Label text= " Label A" >
18+ < input className= " pt-input" placeholder= " Text input" / >
19+ < / Label>
20+ < Label text= " Label A" muted= " (optional)" >
21+ < input className= " pt-input" placeholder= " Text input" / >
22+ < / Label>
23+ < / div>
24+ ```
25+
26+ ### Inline Label
27+ To place ` label ` text and children elements on same line, add optioanl ` inline ` prop:
28+
29+ ``` html static
30+ <Label inline >
31+ ...
32+ </Label >
33+ ```
34+
35+ ``` jsx
36+ < Label text= " Date of Birth" inline>
37+ < InputGroup
38+ leftIconName= " calendar"
39+ placeholder= " Select date..."
40+ / >
41+ < / Label>
42+ ```
43+
44+ ### Disabled Label
45+
46+ To make ` label ` appear as disabled, add optional ` disabled ` prop:
47+
48+ > Note: This prop will not add ` disabled ` as attribute to it's children elements. You have to add it manualy on form elments (` input ` , ` select ` ) and ` .pt-disabled ` CSS class to input groups.
49+
50+ ``` html static
51+ <Label disabled >
52+ ...
53+ </Label >
54+ ```
55+
56+ ``` jsx
57+ < Label text= " Date of Birth" disabled muted= " (disabled only label)" >
58+ < InputGroup
59+ leftIconName= " calendar"
60+ placeholder= " Select date..."
61+ / >
62+ < / Label>
63+ ```
64+
65+ ``` jsx
66+ < Label text= " Date of Birth" disabled muted= " (with disabled input)" >
67+ < InputGroup
68+ disabled
69+ leftIconName= " calendar"
70+ placeholder= " Select date..."
71+ / >
72+ < / Label>
73+ ```
Original file line number Diff line number Diff line change 1+ export { default as Label } from './Label' ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export { ButtonGroup } from './components/ButtonGroup';
22export { Callout } from './components/Callout' ;
33export { Card } from './components/Card' ;
44export { ControlGroup } from './components/ControlGroup' ;
5+ export { Label } from './components/Label' ;
56export { Navbar } from './components/Navbar' ;
67export { NavbarDivider } from './components/NavbarDivider' ;
78export { NavbarGroup } from './components/NavbarGroup' ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 Callout ,
1111 Card ,
1212 ControlGroup ,
13+ Label ,
1314 Navbar ,
1415 NavbarGroup ,
1516 NavbarHeading ,
@@ -19,6 +20,7 @@ global.ButtonGroup = ButtonGroup;
1920global . Callout = Callout ;
2021global . Card = Card ;
2122global . ControlGroup = ControlGroup ;
23+ global . Label = Label ;
2224global . Navbar = Navbar ;
2325global . NavbarGroup = NavbarGroup ;
2426global . NavbarHeading = NavbarHeading ;
You can’t perform that action at this time.
0 commit comments