Skip to content

Commit

Permalink
Fix legacy popover prop problem
Browse files Browse the repository at this point in the history
  • Loading branch information
markdoeswork committed Jul 25, 2024
1 parent 6da47e3 commit 177a96e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
15 changes: 10 additions & 5 deletions playbook/app/pb_kits/playbook/pb_popover/_popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import classnames from "classnames";
import { globalProps, GlobalProps } from "../utilities/globalProps";
import _uniqueId from 'lodash/uniqueId';

type ModifiedGlobalProps = Omit<GlobalProps, 'minWidth'>

type PbPopoverProps = {
aria?: { [key: string]: string };
className?: string;
Expand All @@ -32,7 +34,7 @@ type PbPopoverProps = {
reference: PopperReference & any;
show?: boolean;
shouldClosePopover?: (arg0: boolean) => void;
} & GlobalProps & Omit<PopperProps<any>, 'children'>
} & ModifiedGlobalProps & Omit<PopperProps<any>, 'children'>
& { children?: React.ReactChild[] | React.ReactChild }

// Prop enabled default modifiers here
Expand Down Expand Up @@ -80,10 +82,13 @@ const Popover = (props: PbPopoverProps) => {
targetId,
} = props;

const items = globalProps(props).split(' '); // Split the string into an array of items
const filteredItems = items.filter(item => !item.includes('min_width')); // Filter out items with 'min_width'
const filteredGlobalProps = filteredItems.join(' '); // Join the filtered items back into a string
const popoverSpacing =
globalProps(props).includes("dark") || !globalProps(props)
filteredGlobalProps.includes("dark") || !filteredGlobalProps
? "p_sm"
: globalProps(props);
: filteredGlobalProps
const overflowHandling = maxHeight || maxWidth ? "overflow_handling" : "";
const zIndexStyle = zIndex ? { zIndex: zIndex } : {};
const widthHeightStyles = () => {
Expand All @@ -100,7 +105,7 @@ const Popover = (props: PbPopoverProps) => {
const htmlProps = buildHtmlProps(htmlOptions);
const classes = classnames(
buildCss("pb_popover_kit"),
globalProps(props),
filteredGlobalProps,
className
);

Expand Down Expand Up @@ -250,4 +255,4 @@ const PbReactPopover = (props: PbPopoverProps): React.ReactElement => {
);
};

export default PbReactPopover;
export default PbReactPopover;
11 changes: 10 additions & 1 deletion playbook/app/pb_kits/playbook/utilities/globalProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ type MaxWidth = {
maxWidth?: Sizes,
}

type MinWidth = {
minWidth?: Sizes,
}

type NumberSpacing = {
numberSpacing?: "tabular",
}
Expand Down Expand Up @@ -170,7 +174,7 @@ type ZIndex = {
export type GlobalProps = AlignContent & AlignItems & AlignSelf &
BorderRadius & Cursor & Dark & Display & DisplaySizes & Flex & FlexDirection &
FlexGrow & FlexShrink & FlexWrap & JustifyContent & JustifySelf &
LineHeight & Margin & MaxWidth & NumberSpacing & Order & Overflow & Padding &
LineHeight & Margin & MinWidth & MaxWidth & NumberSpacing & Order & Overflow & Padding &
Position & Shadow & TextAlign & Truncate & VerticalAlign & ZIndex & { hover?: string } & Top & Right & Bottom & Left;

const getResponsivePropClasses = (prop: {[key: string]: string}, classPrefix: string) => {
Expand Down Expand Up @@ -320,6 +324,11 @@ const PROP_CATEGORIES: {[key:string]: (props: {[key: string]: any}) => string} =
css += numberSpacing ? `ns_${numberSpacing} ` : ''
return css
},
minWidthProps: ({ minWidth }: MinWidth) => {
let css = ''
css += minWidth ? `min_width_${minWidth } ` : ''
return css
},
maxWidthProps: ({ maxWidth }: MaxWidth) => {
let css = ''
css += maxWidth ? `max_width_${maxWidth } ` : ''
Expand Down
2 changes: 0 additions & 2 deletions playbook/lib/playbook/spacing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def min_width_props

selected_minw_props.map do |k|
width_value = send(k)
puts "min_width_value: ", width_value
"min_width_#{width_value}" if min_width_values.include? width_value
end.compact.join(" ")
end
Expand All @@ -115,7 +114,6 @@ def max_width_props

selected_mw_props.map do |k|
width_value = send(k)
puts "max_width_value: ", width_value
"max_width_#{width_value}" if max_width_values.include? width_value
end.compact.join(" ")
end
Expand Down

0 comments on commit 177a96e

Please sign in to comment.