A label is a container for labels, description and tooltip. It has a generic structure and styling for form fields.
As a basic example, you can use label and description both as string values.
To set up a tooltip, you can use tooltip and tooltipPlacement. The tooltipPlacement has a default value of bottom
To make the label look required, you can use the required parameter.
Label can have an extra optional label content. By default it is the text "Optional". To change this text, you can use the optionalLabel parameter.
You can use the subtle parameter to make the label a bit more subtle.
To make the label look disabled, you can use the disabled parameter.
You can choose different sizes for the label. Default is sm.
import { DapDSLabel } from 'dap-design-system'
import { DapDSLabelReact } from 'dap-design-system/react'
For optimal bundle sizes, use the tree-shakeable import syntax:
import { DapDSLabel } from 'dap-design-system/components'
| Property | Type | Default | Description |
|---|---|---|---|
label | string | The label text | |
description | string | The description of the label | |
tooltip | string | The tooltip text | |
size | 'xs', 'sm' , 'lg' | The size of the input. Default is sm. | |
tooltipPlacement | 'top', 'right' , 'bottom' , 'left' | The tooltip placement of the label. | |
optional | boolean | If the label is optional. Default value is false. | |
optionalLabel | string | Label of optional text | |
subtle | boolean | Text weight of label. If true the label is subtle. Default value is false. | |
disabled | boolean | The disabled state of the label. Default is false. | |
required | boolean | The required state of the label. Default is false. |
No slots available.
No custom events available.
| Part Name | Description |
|---|---|
base | The main label container. |
label | Tha main label container. dap-ds-form-label element. |
label-base | The label text. |
label-required | The required indicator of the label. |
label-optional | The optional indicator of the label. |
tooltip | The tooltip of the label. dap-ds-tooltip element. |
description | The description of the label. |
You can style CSS parts using the ::part() pseudo-element selector:
/* Target a specific part */
.my-custom-dap-ds-label::part(base) {
/* Your custom styles */
}
/* Target multiple parts */
.my-custom-dap-ds-label::part(base),
.my-custom-dap-ds-label::part(label) {
/* Shared styles */
}
Example usage:
<dap-ds-label class="my-custom-dap-ds-label">
Label
</dap-ds-label>
.my-custom-dap-ds-label::part(base) {
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.
| Property Name | Description |
|---|---|
--dds-label-background | The background color of the label container. Default is `var(--dds-background-neutral-subtle)`. |
--dds-label-border-color | The border color of the label container. Default is `var(--dds-border-neutral-subtle)`. |
--dds-label-border-width | The border width of the label container. Default is `var(--dds-border-width-base)`. |
--dds-label-border-radius | The border radius of the label container. Default is `var(--dds-radius-base)`. |
--dds-label-padding | The padding of the label container. Default is `var(--dds-spacing-400)`. |
--dds-label-disabled-background | The background color of the label container when disabled. Default is `var(--dds-background-neutral-disabled-inverted)`. |
--dds-label-checked-border-color | The border color of the label container when checked. Default is `var(--dds-background-brand-base-inverted)`. |
CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:
Method 1: Inline styles (Quick customization)
<dap-ds-label
style="--dds-label-background: value; --dds-label-border-color: value;">
Label
</dap-ds-label>
Method 2: CSS classes (Reusable styles)
.my-custom-dap-ds-label {
--dds-label-background: value;
--dds-label-border-color: value;
--dds-label-border-width: value;
}
<dap-ds-label class="my-custom-dap-ds-label">
Label
</dap-ds-label>
Method 3: Global theme customization
/* Apply to all instances */
dap-ds-label {
--dds-label-background: value;
--dds-label-border-color: value;
}
CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.