Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[PLAY-1581] Height, minHeight, maxHeight for Card, Flex, FlexItem, & Dialog" #3842

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions playbook/app/pb_kits/playbook/pb_card/_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { get } from 'lodash'
import classnames from 'classnames'

import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
import { GlobalProps, globalProps, globalInlineProps } from '../utilities/globalProps'
import { GlobalProps, globalProps } from '../utilities/globalProps'
import type { ProductColors, CategoryColors, BackgroundColors } from '../types/colors'

import Icon from '../pb_icon/_icon'
Expand Down Expand Up @@ -49,7 +49,6 @@ type CardBodyProps = {
padding?: string,
} & GlobalProps


// Header component
const Header = (props: CardHeaderProps) => {
const { children, className, headerColor = 'category_1', headerColorStriped = false } = props
Expand Down Expand Up @@ -108,7 +107,6 @@ const Card = (props: CardPropTypes): React.ReactElement => {

// coerce to array
const cardChildren = React.Children.toArray(children)
const dynamicInlineProps = globalInlineProps(props);

const subComponentTags = (tagName: string) => {
return cardChildren.filter((c: string) => (
Expand Down Expand Up @@ -137,7 +135,6 @@ const Card = (props: CardPropTypes): React.ReactElement => {
{...dataProps}
{...htmlProps}
className={classnames(cardCss, globalProps(props), className)}
style={dynamicInlineProps}
>
{subComponentTags('Header')}
{
Expand Down Expand Up @@ -166,7 +163,6 @@ const Card = (props: CardPropTypes): React.ReactElement => {
{...dataProps}
{...htmlProps}
className={classnames(cardCss, globalProps(props), className)}
style={dynamicInlineProps}
>
{subComponentTags('Header')}
{nonHeaderChildren}
Expand Down
6 changes: 1 addition & 5 deletions playbook/app/pb_kits/playbook/pb_dialog/_dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from "classnames";
import Modal from "react-modal";

import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props";
import { globalProps, globalInlineProps } from "../utilities/globalProps";
import { globalProps } from "../utilities/globalProps";

import Body from "../pb_body/_body";
import Button from "../pb_button/_button";
Expand Down Expand Up @@ -91,8 +91,6 @@ const Dialog = (props: DialogProps): React.ReactElement => {
beforeClose: "pb_dialog_overlay_before_close",
};

const dynamicInlineProps = globalInlineProps(props);

const classes = classnames(
buildCss("pb_dialog_wrapper"),
globalProps(props),
Expand Down Expand Up @@ -186,7 +184,6 @@ const Dialog = (props: DialogProps): React.ReactElement => {
overlayClassName={overlayClassNames}
portalClassName={portalClassName}
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick && !loading}
style={{ content: dynamicInlineProps }}
>
<>
{title && !status ? <Dialog.Header>{title}</Dialog.Header> : null}
Expand All @@ -195,7 +192,6 @@ const Dialog = (props: DialogProps): React.ReactElement => {
<Dialog.Body
className="dialog_status_text_align"
padding="md"

>
<Flex align="center"
orientation="column"
Expand Down
4 changes: 1 addition & 3 deletions playbook/app/pb_kits/playbook/pb_flex/_flex.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import classnames from 'classnames'
import { buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
import { GlobalProps, globalProps, globalInlineProps } from '../utilities/globalProps'
import { GlobalProps, globalProps } from '../utilities/globalProps'
import { GenericObject, Sizes } from '../types'

type FlexProps = {
Expand Down Expand Up @@ -61,7 +61,6 @@ const Flex = (props: FlexProps): React.ReactElement => {
const alignSelfClass = alignSelf !== 'none' ? `align_self_${alignSelf}` : ''
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
const dynamicInlineProps = globalInlineProps(props)


return (
Expand All @@ -84,7 +83,6 @@ const Flex = (props: FlexProps): React.ReactElement => {
globalProps(props),
className
)}
style={dynamicInlineProps}
{...dataProps}
{...htmlProps}
>
Expand Down
10 changes: 2 additions & 8 deletions playbook/app/pb_kits/playbook/pb_flex/_flex_item.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import classnames from 'classnames'
import { buildCss, buildHtmlProps } from '../utilities/props'
import { globalProps, GlobalProps, globalInlineProps} from '../utilities/globalProps'
import { globalProps, GlobalProps } from '../utilities/globalProps'
type FlexItemPropTypes = {
children: React.ReactNode[] | React.ReactNode,
fixedSize?: string,
Expand Down Expand Up @@ -35,20 +35,14 @@ const FlexItem = (props: FlexItemPropTypes): React.ReactElement => {
const fixedStyle =
fixedSize !== undefined ? { flexBasis: `${fixedSize}` } : null
const orderClass = order !== 'none' ? `order_${order}` : null
const dynamicInlineProps = globalInlineProps(props)
const combinedStyles = {
...fixedStyle,
...dynamicInlineProps
}

const htmlProps = buildHtmlProps(htmlOptions)


return (
<div
{...htmlProps}
className={classnames(buildCss('pb_flex_item_kit', growClass, shrinkClass, flexClass, displayFlexClass), orderClass, alignSelfClass, globalProps(props), className)}
style={combinedStyles}
style={fixedStyle}
>
{children}
</div>
Expand Down
9 changes: 6 additions & 3 deletions playbook/app/pb_kits/playbook/pb_flex/flex_item.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<%= pb_content_tag(:div,
style: object.inline_styles
) do %>
<%= content_tag(:div,
id: object.id,
data: object.data,
class: object.classname,
style: object.style_value,
**combined_html_options) do %>
<%= content.presence %>
<% end %>
9 changes: 2 additions & 7 deletions playbook/app/pb_kits/playbook/pb_flex/flex_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ def classname
generate_classname("pb_flex_item_kit", fixed_size_class, grow_class, shrink_class, display_flex_class) + align_self_class
end

def inline_styles
styles = []
styles << "flex-basis: #{fixed_size};" if fixed_size.present?
styles << "height: #{height};" if height.present?
styles << "min-height: #{min_height};" if min_height.present?
styles << "max-height: #{max_height};" if max_height.present?
styles.join(" ")
def style_value
"flex-basis: #{fixed_size};" if fixed_size.present?
end

private
Expand Down
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_popover/_popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import classnames from "classnames";
import { globalProps, GlobalProps } from "../utilities/globalProps";
import { uniqueId } from 'lodash';

type ModifiedGlobalProps = Omit<GlobalProps, 'minWidth' | 'maxHeight' | 'minHeight'>
type ModifiedGlobalProps = Omit<GlobalProps, 'minWidth'>

type PbPopoverProps = {
aria?: { [key: string]: string };
Expand Down
3 changes: 0 additions & 3 deletions playbook/app/pb_kits/playbook/utilities/globalPropNames.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export default [
"minHeight",
"maxHeight",
"height",
"left",
"bottom",
"right",
Expand Down
41 changes: 2 additions & 39 deletions playbook/app/pb_kits/playbook/utilities/globalProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,12 @@ type ZIndex = {
zIndex?: ZIndexType,
} | ZIndexResponsiveType

type Height = {
height?: string
}

type MaxHeight = {
maxHeight?: string
}

type MinHeight = {
minHeight?: string
}

// keep this as the last type definition
export type GlobalProps = AlignContent & AlignItems & AlignSelf &
BorderRadius & Cursor & Dark & Display & DisplaySizes & Flex & FlexDirection &
FlexGrow & FlexShrink & FlexWrap & JustifyContent & JustifySelf &
LineHeight & Margin & MinWidth & MaxWidth & NumberSpacing & Order & Overflow & Padding &
Position & Shadow & TextAlign & Truncate & VerticalAlign & ZIndex & { hover?: string } & Top & Right & Bottom & Left & Height & MaxHeight & MinHeight;
Position & Shadow & TextAlign & Truncate & VerticalAlign & ZIndex & { hover?: string } & Top & Right & Bottom & Left;

const getResponsivePropClasses = (prop: {[key: string]: string}, classPrefix: string) => {
const keys: string[] = Object.keys(prop)
Expand Down Expand Up @@ -510,22 +498,7 @@ const PROP_CATEGORIES: {[key:string]: (props: {[key: string]: any}) => string} =
} else {
return verticalAlign ? `vertical_align_${verticalAlign} ` : ''
}
},

}

const PROP_INLINE_CATEGORIES: {[key:string]: (props: {[key: string]: any}) => {[key: string]: any}} = {
heightProps: ({ height }: Height) => {
return height ? { height } : {};
},

maxHeightProps: ({ maxHeight }: MaxHeight) => {
return maxHeight ? { maxHeight } : {};
},

minHeightProps: ({ minHeight }: MinHeight) => {
return minHeight ? { minHeight } : {};
},
}
}

type DefaultProps = {[key: string]: string} | Record<string, unknown>
Expand All @@ -537,16 +510,6 @@ export const globalProps = (props: GlobalProps, defaultProps: DefaultProps = {})
}).filter((value) => value?.length > 0).join(" ")
}

// New function for inline styles
export const globalInlineProps = (props: GlobalProps): React.CSSProperties => {
const styles = Object.keys(PROP_INLINE_CATEGORIES).reduce((acc, key) => {
const result = PROP_INLINE_CATEGORIES[key](props);
return { ...acc, ...(typeof result === 'object' ? result : {}) }; // Ensure result is an object before spreading
}, {});

return styles; // Return the styles object directly
}


export const deprecatedProps = (): void => {
// if (process.env.NODE_ENV === 'development') {
Expand Down
22 changes: 1 addition & 21 deletions playbook/lib/playbook/kit_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ class KitBase < ViewComponent::Base
prop :aria, type: Playbook::Props::HashProp, default: {}
prop :html_options, type: Playbook::Props::HashProp, default: {}
prop :children, type: Playbook::Props::Proc
prop :style, type: Playbook::Props::HashProp, default: {}
prop :height
prop :min_height
prop :max_height

def object
self
Expand All @@ -86,14 +82,6 @@ def combined_html_options
default_html_options.merge(html_options.deep_merge(data_attributes))
end

def global_inline_props
{
height: height,
min_height: min_height,
max_height: max_height,
}.compact
end

# rubocop:disable Layout/CommentIndentation
# pb_content_tag information (potentially to be abstracted into its own dev doc in the future)
# The pb_content_tag generates HTML content tags for rails kits with flexible options.
Expand Down Expand Up @@ -125,15 +113,12 @@ def pb_content_tag(name = :div, content_or_options_with_block = {}, options = {}
private

def default_options
options = {
{
id: id,
data: data,
class: classname,
aria: aria,
}
inline_styles = dynamic_inline_props
options[:style] = inline_styles if inline_styles.present?
options
end

def default_html_options
Expand All @@ -146,10 +131,5 @@ def data_attributes
aria: aria,
}.transform_keys { |key| key.to_s.tr("_", "-").to_sym }
end

def dynamic_inline_props
styles = global_inline_props.map { |key, value| "#{key.to_s.gsub('_', '-')}: #{value};" if value.present? }.compact
styles.join(" ").presence
end
end
end
Loading