From a04ad24b3ea998885ee74cd8bb76d2f48c9a0c52 Mon Sep 17 00:00:00 2001 From: Elisa Shapiro <83474365+ElisaShapiro@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:38:40 -0400 Subject: [PATCH] [PBNTR-595] Follow up to Fixed Width Filter issue on Templates (#3827) **What does this PR do?** A clear and concise description with your runway ticket url. [PBNTR-595](https://runway.powerhrg.com/backlog_items/PBNTR-595) implements the popoverProps component on the Filter kit which will unblock PBNTR's template work by allowing the team to set an optimal Filter Popover width on our templates without using inline styling or a separate scss file. PopoverProps are connected to the embedded Popover within the Filter kit (by spreading the popoverProps prop React, and by merging popover_props to the rest of the props in Rails). A "Popover Props" doc example has been added to the Rails and React kit pages which shows using the popover prop to set a custom width on the filter popover. The Popover kit itself now accepts a width prop to allow us to achieve this - no doc example necessary at this time. This is associated with an [alpha PR here](linktocome) to demonstrate its use to prevent the Rails template popover width from jumping every time an item is added to the Filter's Typeahead. **Screenshots:** Screenshots to visualize your addition/change Rails Popover Props doc example for PR popover props doc ex rails React Popover Props doc example for PR popover props doc ex react Rails Template with `popover_props` applying a set width to avoid the filter popover jumping with each additional typeahead entry desktop+mobile for PR rails template desktop filter fixed width for PR rails template mobile filter fixed width **How to test?** Steps to confirm the desired behavior: 1. Go to the filter kit review env page, specifically to the Popover Props doc example ([rails](https://pr3827.playbook.beta.px.powerapp.cloud/kits/filter#popover-props), [react](https://pr3827.playbook.beta.px.powerapp.cloud/kits/filter/react#popover-props)) 2. Click on Filter popover button and see a smaller-than-usual Filter popover appear. Compare to other doc examples on the page (default, etc.) to see the difference. 3. Go to the [rails template page](https://pr43315.nitro-web.beta.hq.powerapp.cloud/dev_docs/playbook/templates/demos/basic_table/rails) in the review environment with alpha from this PR. 4. Open the Filter and add several items to the typeahead. The width of the popover should not jump with every additional entry. #### 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.~~ --- .../pb_filter/Filter/FilterDouble.tsx | 2 + .../pb_filter/Filter/FilterSingle.tsx | 2 + .../pb_filter/Filter/FiltersPopover.tsx | 5 +- .../docs/_filter_popover_props.html.erb | 41 +++++++++++ .../pb_filter/docs/_filter_popover_props.jsx | 71 +++++++++++++++++++ .../docs/_filter_popover_props_rails.md | 1 + .../docs/_filter_popover_props_react.md | 1 + .../playbook/pb_filter/docs/example.yml | 3 + .../pb_kits/playbook/pb_filter/docs/index.js | 1 + .../playbook/pb_filter/filter.html.erb | 4 +- .../app/pb_kits/playbook/pb_filter/filter.rb | 2 + .../pb_kits/playbook/pb_popover/_popover.tsx | 6 +- .../pb_popover/docs/_popover_default.html.erb | 2 +- .../pb_kits/playbook/pb_popover/popover.rb | 4 +- 14 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.html.erb create mode 100644 playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.jsx create mode 100644 playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props_rails.md create mode 100644 playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props_react.md diff --git a/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterDouble.tsx b/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterDouble.tsx index 7d15d84d12..ecb21b72ad 100644 --- a/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterDouble.tsx +++ b/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterDouble.tsx @@ -34,6 +34,7 @@ const FilterDouble = ({ maxHeight, minWidth, placement, + popoverProps, ...bgProps }: FilterDoubleProps): React.ReactElement => ( {children} diff --git a/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterSingle.tsx b/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterSingle.tsx index 4d8b285f01..950575006b 100644 --- a/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterSingle.tsx +++ b/playbook/app/pb_kits/playbook/pb_filter/Filter/FilterSingle.tsx @@ -33,6 +33,7 @@ const FilterSingle = ({ maxHeight, minWidth, placement, + popoverProps, ...bgProps }: FilterSingleProps): React.ReactElement => { return ( @@ -52,6 +53,7 @@ const FilterSingle = ({ maxHeight={maxHeight} minWidth={minWidth} placement={placement} + popoverProps={popoverProps} > {children} diff --git a/playbook/app/pb_kits/playbook/pb_filter/Filter/FiltersPopover.tsx b/playbook/app/pb_kits/playbook/pb_filter/Filter/FiltersPopover.tsx index 72ce03420a..362915bcc0 100644 --- a/playbook/app/pb_kits/playbook/pb_filter/Filter/FiltersPopover.tsx +++ b/playbook/app/pb_kits/playbook/pb_filter/Filter/FiltersPopover.tsx @@ -2,6 +2,7 @@ import React, { ReactNode, useState } from 'react' import CircleIconButton from '../../pb_circle_icon_button/_circle_icon_button' import PbReactPopover from '../../pb_popover/_popover' +import { GenericObject } from '../../types' type FiltersPopoverProps = { children?: React.ReactChild[] | React.ReactChild | (({closePopover}: {closePopover: () => void}) => ReactNode), @@ -9,8 +10,9 @@ type FiltersPopoverProps = { maxHeight?: string, minWidth?: string, placement?: "top" | "right" | "bottom" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end", + popoverProps?: GenericObject, } -const FiltersPopover = ({ children, dark, maxHeight, minWidth, placement = "bottom-start" }: FiltersPopoverProps): React.ReactElement => { +const FiltersPopover = ({ children, dark, maxHeight, minWidth, placement = "bottom-start", popoverProps }: FiltersPopoverProps): React.ReactElement => { const [hide, updateHide] = useState(true) const toggle = () => updateHide(!hide) @@ -33,6 +35,7 @@ const FiltersPopover = ({ children, dark, maxHeight, minWidth, placement = "bott reference={filterButton} shouldClosePopover={updateHide} show={!hide} + {...popoverProps} >
{typeof children === 'function' diff --git a/playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.html.erb b/playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.html.erb new file mode 100644 index 0000000000..da96315cce --- /dev/null +++ b/playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.html.erb @@ -0,0 +1,41 @@ +<%= + pb_rails("filter", props: { + id: "filter_popover_props", + position: "top", + filters: [ + { name: "name", value: "John Wick" }, + { name: "city", value: "San Francisco"} + ], + sort_menu: [ + { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, + { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, + { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, + ], + template: "default", + results: 1, + popover_props: { width: "250px" }, + }) do +%> + <% + example_collection = [ + OpenStruct.new(name: "USA", value: 1), + OpenStruct.new(name: "Canada", value: 2), + OpenStruct.new(name: "Brazil", value: 3), + OpenStruct.new(name: "Philippines", value: 4), + OpenStruct.new(name: "A galaxy far far away, like really far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far away...", value: 5) + ] + %> + <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> + <%= form.text_field :example_text_field, props: { label: true } %> + <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: {max_width: "sm", label: true } %> + + <%= form.actions do |action| %> + <%= action.submit props: { + text: "Apply", + data: { + disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe + },}%> + <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> + <% end %> + <% end %> +<% end %> diff --git a/playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.jsx b/playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.jsx new file mode 100644 index 0000000000..d98bb00b04 --- /dev/null +++ b/playbook/app/pb_kits/playbook/pb_filter/docs/_filter_popover_props.jsx @@ -0,0 +1,71 @@ +import React from 'react' +import { Button, Filter, Flex, Select, TextInput } from 'playbook-ui' + +const FilterPopoverProps = (props) => { + const options = [ + { value: 'USA' }, + { value: 'Canada' }, + { value: 'Brazil' }, + { value: 'Philippines' }, + { value: 'A galaxy far far away, like really far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far away...' }, + ] + + const popoverProps = { + width: "250px" + } + + return ( + + {({ closePopover }) => ( +
+ +