Skip to content

Commit

Permalink
[PBNTR-389](Dropdown work - States & Variant Prop [ 1 of 5]) (#3828)
Browse files Browse the repository at this point in the history
[PBNTR-389](https://runway.powerhrg.com/backlog_items/PBNTR-389)

This PR adds new state styles and a variant prop with a subtle doc
example!

<img width="754" alt="Screenshot 2024-09-30 at 2 04 45 PM"
src="https://github.com/user-attachments/assets/1a732f3b-ab25-4fd4-ba6f-547ff26bf05a">



**How to test?** Steps to confirm the desired behavior:
1. Go to the dropdown kit and confirm styles!

#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [x] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
- [ ] **TESTS** I have added test coverage to my code.
  • Loading branch information
nickamantia authored Oct 22, 2024
1 parent 693a86c commit f4c5e2f
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 5 deletions.
87 changes: 84 additions & 3 deletions playbook/app/pb_kits/playbook/pb_dropdown/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@
padding-bottom: $space_xs;
cursor: pointer;
&:hover {
background-color: $border_light;
background-color: $bg_light;
}

&[class*="_focused"] {
background-color: $border_light;
background-color: $bg_light;
}

&[class*="_list"] {
border-bottom: 1px solid $border_light;

&:hover, &:focus {
.pb_body_kit {
color: $primary;
}
}
}
&[class*="selected"] {
background-color: $primary;
Expand All @@ -87,7 +93,7 @@
color: $white !important;
}
&:hover {
background-color: $primary !important;
background-color: $product_1_background !important;
}
}
}
Expand Down Expand Up @@ -125,6 +131,81 @@
}
}

&.separators_hidden {
.dropdown_wrapper {
.pb_dropdown_container {

[class*="pb_dropdown_option"] {
border: none;
}
}
}
}

&.subtle {
.dropdown_wrapper {
.pb_dropdown_container {

[class*="pb_dropdown_option"]:first-child {
margin-top: $space_xs;
}

[class*="pb_dropdown_option"]:last-child {
margin-bottom: $space_xs;
}

[class*="pb_dropdown_option"] {
margin: $space_xs;
padding: $space_xs;
border-radius: $border_radius_md;
border-bottom: none;
position: relative;

&::after {
content: "";
position: absolute;
left: -$space_xs;
right: -$space_xs;
bottom: -4.5px;
height: 1px;
background: $border_light;
}
}

[class*="pb_dropdown_option"]:last-child::after {
display: none;
}
}
}

&.separators_hidden {
.dropdown_wrapper {
.pb_dropdown_container {
[class*="pb_dropdown_option"]:first-child {
margin-top: $space_xs;
}

[class*="pb_dropdown_option"]:last-child {
margin-bottom: $space_xs;
}

[class*="pb_dropdown_option"] {
padding: $space_xxs $space_xs;
margin: $space_xxs $space_xs;

&::after {
height: 0px;
}

&[class*="selected"] {
border-bottom: none;
}
}
}
}
}
}

&.dark {
.dropdown_wrapper {
[class*="dropdown_trigger_wrapper"] {
Expand Down
9 changes: 8 additions & 1 deletion playbook/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ type DropdownProps = {
label?: string;
onSelect?: (arg: GenericObject) => null;
options: GenericObject;
separators: boolean;
triggerRef?: any;
variant?: "default" | "subtle";
};

interface DropdownComponent
Expand All @@ -62,15 +64,20 @@ const Dropdown = forwardRef((props: DropdownProps, ref: any) => {
label,
onSelect,
options,
triggerRef
separators = true,
triggerRef,
variant = "default",
} = props;

const ariaProps = buildAriaProps(aria);
const dataProps = buildDataProps(data);
const htmlProps = buildHtmlProps(htmlOptions);
const separatorsClass = separators ? '' : 'separators_hidden'
const classes = classnames(
buildCss("pb_dropdown"),
globalProps(props),
variant,
separatorsClass,
className
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%
options = [
{ label: 'United States', value: 'United States', id: 'us' },
{ label: 'Canada', value: 'Canada', id: 'ca' },
{ label: 'Pakistan', value: 'Pakistan', id: 'pk' },
]

%>
<%= pb_rails("dropdown", props: {options: options, separators: false}) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { Dropdown } from 'playbook-ui'

const DropdownSeparatorsHidden = (props) => {

const options = [
{
label: "United States",
value: "United States",
},
{
label: "Canada",
value: "Canada",
},
{
label: "Pakistan",
value: "Pakistan",
}
];


return (
<div>
<Dropdown
options={options}
separators={false}
{...props}
/>
</div>
)
}

export default DropdownSeparatorsHidden
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%
options = [
{ label: 'United States', value: 'United States', id: 'us' },
{ label: 'Canada', value: 'Canada', id: 'ca' },
{ label: 'Pakistan', value: 'Pakistan', id: 'pk' },
]

%>

<%= pb_rails("dropdown", props: { options: options, variant: "subtle", separators: false }) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import { Dropdown } from 'playbook-ui'

const DropdownSubtleVariant = (props) => {

const options = [
{
label: "United States",
value: "United States",
},
{
label: "Canada",
value: "Canada",
},
{
label: "Pakistan",
value: "Pakistan",
}
];


return (
<>
<Dropdown
options={options}
separators={false}
variant="subtle"
{...props}
/>
</>
)
}

export default DropdownSubtleVariant
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For the `subtle` variant, it is recommended that you set the `Separators` prop to `false` to remove the separator lines between the options for a more cleaner look.
4 changes: 4 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dropdown/docs/example.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
examples:
rails:
- dropdown_default: Default
- dropdown_subtle_variant: Subtle Variant
- dropdown_subcomponent_structure_rails: Subcomponent Structure
- dropdown_with_label: With Label
- dropdown_with_custom_options_rails: Custom Options
Expand All @@ -10,9 +11,11 @@ examples:
- dropdown_error: Dropdown with Error
- dropdown_default_value: Default Value
- dropdown_blank_selection: Blank Selection
- dropdown_separators_hidden: Separators Hidden

react:
- dropdown_default: Default
- dropdown_subtle_variant: Subtle Variant
- dropdown_subcomponent_structure: Subcomponent Structure
- dropdown_with_label: With Label
- dropdown_with_custom_options: Custom Options
Expand All @@ -23,6 +26,7 @@ examples:
- dropdown_default_value: Default Value
- dropdown_blank_selection: Blank Selection
- dropdown_clear_selection: Clear Selection
- dropdown_separators_hidden: Separators Hidden
# - dropdown_with_autocomplete: Autocomplete
# - dropdown_with_autocomplete_and_custom_display: Autocomplete with Custom Display
# - dropdown_with_external_control: useDropdown Hook
Expand Down
2 changes: 2 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dropdown/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export { default as DropdownError } from './_dropdown_error.jsx'
export { default as DropdownDefaultValue } from './_dropdown_default_value.jsx'
export { default as DropdownBlankSelection } from './_dropdown_blank_selection.jsx'
export { default as DropdownClearSelection } from './_dropdown_clear_selection.jsx'
export { default as DropdownSubtleVariant } from './_dropdown_subtle_variant.jsx'
export { default as DropdownSeparatorsHidden } from './_dropdown_separators_hidden.jsx'
11 changes: 10 additions & 1 deletion playbook/app/pb_kits/playbook/pb_dropdown/dropdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ class Dropdown < Playbook::KitBase
prop :default_value
prop :blank_selection, type: Playbook::Props::String,
default: ""
prop :variant, type: Playbook::Props::Enum,
values: %w[default subtle],
default: "default"
prop :separators, type: Playbook::Props::Boolean,
default: true

def data
Hash(prop(:data)).merge(pb_dropdown: true)
end

def classname
generate_classname("pb_dropdown")
generate_classname("pb_dropdown", variant, separators_class, separator: " ")
end

private
Expand All @@ -32,6 +37,10 @@ def input_default_value
default_value.present? ? default_value.transform_keys(&:to_s)["id"] : ""
end

def separators_class
separators ? "" : "separators_hidden"
end

def options_with_blank
blank_selection.present? ? [{ id: "", value: "", label: blank_selection }] + options : options
end
Expand Down

0 comments on commit f4c5e2f

Please sign in to comment.