Add VisualPicker component
See original GitHub issueThe Lightning Reports team would like to implement the <VisualPicker/>
component. We will consume it as part of a new feature in 220.
For reference, the Visual Picker spec is here: https://latest-220.lightningdesignsystem.com/components/visual-picker/
Here are the props proposition:
static propTypes = {
/**
* **Assistive text for accessibility**
* This object is merged with the default props object on every render.
* * `label`: This is used as a visually hidden label if, no `labels.label` is provided.
* * `icon`: Text for checkmark icon on selected item(s).
* * `selectedItemLabel`: This is used as a visually hidden label of selected item(s). The default is `Current Selection:`.
*/
assistiveText: PropTypes.shape({
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
icon: PropTypes.string,
selectedItemLabel: PropTypes.string
}),
/**
* CSS classes to be added to tag with `.slds-visual-picker`.
*/
className: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
/**
* CSS classes to be added to tag with `.slds-visual-picker__body`.
*/
classNameBody: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
/**
* CSS classes to be added to top level tag with `.slds-form-element`.
*/
classNameContainer: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
/**
* Event Callbacks
* * `onBlur`: Called when `input` removes focus.
* * `onFocus`: Called when `input` receives focus.
* * `onRequestRemoveSelectedOption`: Function called when selected option is to be removed.
* * `onSelect`: Function called when item is selected.
*/
events: PropTypes.shape({
onBlur: PropTypes.func,
onFocus: PropTypes.func,
onRequestRemoveSelectedOption: PropTypes.func,
onSelect: PropTypes.func,
}),
/**
* HTML id for component.
*/
id: PropTypes.string,
/**
* **Text labels for internationalization**
* This object is merged with the default props object on every render.
* * `label`: This label appears above the component.
*/
labels: PropTypes.shape({
label: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
}),
/**
* **Array of item objects**
* Each object can contain:
* * `id`: A unique identifier string.
* * `label`: A primary string of text for the heading of an item.
* * `title`: A secondary string of text that renders as a sibling the `label` element.
* * `visualIndicator`: A node displaying a visual indicator for the item. Not available with `variant=vertical`.
*
*/
options: PropTypes.arrayOf(
PropTypes.PropTypes.shape({
id: PropTypes.string.isRequired,
label: PropTypes.string,
title: PropTypes.string,
visualIndicator: PropTypes.nodes
})
).isRequired
/**
* Adds required (*) styling to label.
*/
required: PropTypes.bool,
/**
* Selected item object.
* * `id`: A unique identifier string.
* * `label`: A primary string of text for the heading of an item.
* * `title`: A secondary string of text that renders as a sibling the `label` element.
* * `visualIndicator`: A node displaying a visual indicator for the item. Not available with `variant=vertical`.
*/
selection: PropTypes.shape({
id: PropTypes.string.isRequired,
label: PropTypes.string,
title: PropTypes.string,
visualIndicator: PropTypes.nodes
}),
/**
* The type of visual picker. The default is `coverableContent`.
*/
variant: PropTypes.oneOf(['coverableContent', 'link', 'nonCoverableContent', 'vertical']).isRequired,
};
static defaultProps = {
selectedItemLabel: 'Current Selection:'
variant: 'coverableContent'
};
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Visual Picker - Lightning Design System
A visual picker can be either radio buttons, checkboxes, or links that are visually enhanced. Add the following object(s).
Read more >Visual Picker in Lightning Web Component Salesforce ️ ️
In this video you will learn how to create Visual Picker in Lightning Web Component. We will use the Lightning Design System to...
Read more >Visual Picker in Lightning Web Component Salesforce ☁️⚡️
In this video you will learn how to create Visual Picker in Lightning Web Component. We will use the Lightning Design System to...
Read more >LWC Visual Pickers - sfdcbox.com
Single select picker works with input type radio and multi select with input type checkbox.
Read more >Make visual picker an aura/lightning component - IdeaExchange
I'm working on adding visual pickers to the quickChoice component on unofficialsf.com. Expand Post. Liked Like
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Spec needs to allow
Each of the variants take different data which makes me think that an
options
array of objects may not be the best implementation.This is a form element at it’s core, so we will need access to
to name a few things that come to mind.
Internal Architecture
I’d like to reuse radio and checkbox with a
visual-picker
variant that creates thediv
wrapper and with a custom render prop calledrenderLabel: Proptype.node
that allows a custom rendering of label fromVisualPicker
. The primary reason is that folks will need access to all radio/checkbox props, especially folks like the Trailhead app that submit actual HTML forms to a server.Core DOM chucks of Visual Picker
The layouts provided by the SLDS site seem really specific to their implementations, especially the non-coverable one, “$150 USD/user/month*”.
This makes me lean toward custom children. Something like:
<NonCoverable>
,<Coverable>
,Link
, andVertical
becomes a child component that takes it’s own unique props. If this component was limited to one of these variants and took the same information, anoptions
array would be the best way to go.What do you think?
@tanhengyeow sure 👍