This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
polaris-labelled.js
101 lines (89 loc) · 1.88 KB
/
polaris-labelled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Component from '@ember/component';
import { computed } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import {
computedErrorId,
computedHelpTextId,
} from '@smile-io/ember-polaris/utils/id';
import layout from '../templates/components/polaris-labelled';
/**
* Internal Polaris labelled component, used to add labels to form fields.
*/
export default Component.extend({
// Tagless component so that Ember doesn't apply the `id`
// attribute to the component's root element.
tagName: '',
layout,
/**
* A unique identifier for the label
* Note that we default this to Ember's GUID for this component instance,
* but the value can be overridden by the outside world.
*
* @type {String}
* @public
*/
id: computed(function() {
return guidFor(this);
}),
/**
* Text for the label
*
* @type {String}
* @public
*/
label: null,
/**
* Error to display beneath the label
*
* @type {String|Component|Boolean}
* @public
*/
error: null,
/**
* An action
*
* @type {Object}
* @public
*/
action: null,
/**
* Additional hint text to display
*
* @type {String|Component}
* @public
*/
helpText: null,
/**
* Visually hide the label
*
* @type {Boolean}
* @default false
* @public
*/
labelHidden: false,
dataTestLabelled: true,
/**
* ID for the error message div
*
* @type {String}
* @private
*/
errorId: computedErrorId('id').readOnly(),
/**
* ID for the help text div
*
* @type {String}
* @private
*/
helpTextId: computedHelpTextId('id').readOnly(),
/**
* Flag indicating whether to render the error component
*
* @type {Boolean}
* @private
*/
shouldRenderError: computed('error', function() {
let error = this.get('error');
return error && typeof error !== 'boolean';
}).readOnly(),
});