Skip to content

Commit

Permalink
[PLAY-1587] Group hover Global Prop (#3833)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
Runway https://runway.powerhrg.com/backlog_items/PLAY-1587

This story adds a new global prop, Group Hover

When you add the `group_hover` prop to a kit and the children inside
that kit. The children's hover effects will take place when the parent
is hovered.

You just need to pass the `group_hover: true` or `groupHover` global
prop to the parent and children(s)

**Screenshots:** Screenshots to visualize your addition/change

![Screenshot 2024-10-31 at 11 11
30 AM](https://github.com/user-attachments/assets/7f119416-8b72-4e5c-b9e9-a7e5732273eb)


**How to test?** Steps to confirm the desired behavior:
1. Go to
https://pr3833.playbook.beta.gm.powerapp.cloud/visual_guidelines/group_hover
2. hover over the card/text in the card to see the different behaviors 

#### 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
markdoeswork authored Nov 7, 2024
1 parent c69799d commit 95eef34
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export const VisualGuidelinesItems = [
name: "Hover",
link: "/visual_guidelines/hover"
},
{
name: "Group Hover",
link: "/visual_guidelines/group_hover"
},
{
name: "Text Align",
link: "/visual_guidelines/text_align"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable flowtype/no-types-missing-file-annotation */

import React from 'react'

import {
Card,
Title,
} from 'playbook-ui'

import Example from '../Templates/Example'

const GroupHoverDescription = () => (
<>
You can hover over a kit and its children's hover affects will be applied. Check out <a href="https://playbook.powerapp.cloud/visual_guidelines/hover">{"our hover affects here."}</a>
</>
)

const GroupHover = ({ example }: {example: string}) => (
<Example
backgroundClass='group-hover-class'
description={<GroupHoverDescription />}
example={example}
title="Group Hover"
>
<Card
cursor="pointer"
groupHover
>
<Title
alignSelf="center"
groupHover
hover={{ scale: "lg"}}
text="If the card is hovered, I'm hovered too!"
/>
<Title
alignSelf="center"
paddingY="lg"
text="I don't have any hover effect on me"
/>
<Title
alignSelf="center"
hover={{ scale: "lg"}}
text="I need to be hovered over directly"
/>
</Card>
</Example>
)

export default GroupHover
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cursor from "../VisualGuidelines/Examples/Cursor";
import FlexBox from "../VisualGuidelines/Examples/FlexBox";
import Position from "../VisualGuidelines/Examples/Position";
import Hover from "../VisualGuidelines/Examples/Hover";
import GroupHover from "../VisualGuidelines/Examples/GroupHover";
import TextAlign from "../VisualGuidelines/Examples/TextAlign";
import Overflow from "./Examples/Overflow";
import Truncate from "./Examples/Truncate";
Expand Down Expand Up @@ -82,6 +83,8 @@ const VisualGuidelines = ({
return <VerticalAlign example={examples.vertical_align_jsx}/>;
case "hover":
return <Hover example={examples.hover_jsx}/>;
case "group_hover":
return <GroupHover example={examples.group_hover_jsx}/>;
case "text_align":
return <TextAlign example={examples.text_align_jsx} />
case "overflow":
Expand Down
21 changes: 21 additions & 0 deletions playbook-website/app/views/pages/code_snippets/group_hover_jsx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Card
cursor="pointer"
groupHover
>
<Title
alignSelf="center"
groupHover
hover={{ scale: "lg"}}
text="If the card is hovered, I'm hovered too!"
/>
<Title
alignSelf="center"
paddingY="lg"
text="I don't have any hover effect on me"
/>
<Title
alignSelf="center"
hover={{ scale: "lg"}}
text="I need to be hovered over directly"
/>
</Card>
89 changes: 46 additions & 43 deletions playbook/app/pb_kits/playbook/utilities/_hover.scss
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
@import "../tokens/exports/scale.module";

@mixin hover-color-classes($colors-list) {
@each $name, $color in $colors-list {
.hover_background_#{"" + $name}:hover {
background-color: $color !important;
transition: background-color $transition-speed ease;
}
.hover_color_#{"" + $name}:hover {
color: $color !important;
transition: color $transition-speed ease;
}
@mixin hover-scale-classes($scales-list) {
@each $name, $scale in $scales-list {
.hover_#{"" + $name}:hover,
.group_hover:hover .group_hover.hover_#{"" + $name} {
transform: $scale;
transition: transform $transition-speed ease;
}
}

@mixin hover-shadow-classes($shadows-list) {
@each $name, $shadow in $shadows-list {
.hover_#{"" + $name}:hover {
box-shadow: $shadow;
transition: box-shadow $transition-speed ease;
}
}

@mixin hover-shadow-classes($shadows-list) {
@each $name, $shadow in $shadows-list {
.hover_#{"" + $name}:hover,
.group_hover:hover .group_hover.hover_#{"" + $name} {
box-shadow: $shadow;
transition: box-shadow $transition-speed ease;
}
}

@mixin hover-scale-classes($scales-list) {
@each $name, $scale in $scales-list {
.hover_#{"" + $name}:hover {
transform: $scale;
transition: transform $transition-speed ease;
}
}

@mixin hover-color-classes($colors-list) {
@each $name, $color in $colors-list {
.hover_background_#{"" + $name}:hover,
.group_hover:hover .group_hover.hover_background_#{"" + $name} {
background-color: $color !important;
transition: background-color $transition-speed ease;
}
.hover_color_#{"" + $name}:hover,
.group_hover:hover .group_hover.hover_color_#{"" + $name} {
color: $color !important;
transition: color $transition-speed ease;
}
}
@include hover-scale-classes($scales);
@include hover-shadow-classes($box_shadows);
@include hover-color-classes($product_colors);
@include hover-color-classes($status_colors);
@include hover-color-classes($data_colors);
@include hover-color-classes($shadow_colors);
@include hover-color-classes($colors);
@include hover-color-classes($interface_colors);
@include hover-color-classes($main_colors);
@include hover-color-classes($background_colors);
@include hover-color-classes($card_colors);
@include hover-color-classes($active_colors);
@include hover-color-classes($action_colors);
@include hover-color-classes($hover_colors);
@include hover-color-classes($border_colors);
@include hover-color-classes($text_colors);
@include hover-color-classes($category_colors);
}

@include hover-scale-classes($scales);
@include hover-shadow-classes($box_shadows);
@include hover-color-classes($product_colors);
@include hover-color-classes($status_colors);
@include hover-color-classes($data_colors);
@include hover-color-classes($shadow_colors);
@include hover-color-classes($colors);
@include hover-color-classes($interface_colors);
@include hover-color-classes($main_colors);
@include hover-color-classes($background_colors);
@include hover-color-classes($card_colors);
@include hover-color-classes($active_colors);
@include hover-color-classes($action_colors);
@include hover-color-classes($hover_colors);
@include hover-color-classes($border_colors);
@include hover-color-classes($text_colors);
@include hover-color-classes($category_colors);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default [
"right",
"top",
"hover",
"groupHover",
"zIndex",
"verticalAlign",
"truncate",
Expand Down
7 changes: 6 additions & 1 deletion playbook/app/pb_kits/playbook/utilities/globalProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ type Hover = Shadow & {
scale?: "sm" | "md" | "lg"
}

type GroupHover = {
groupHover?: boolean,
}

type JustifyContent = {
justifyContent?: Alignment & Space
}
Expand Down Expand Up @@ -175,7 +179,7 @@ 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;
Position & Shadow & TextAlign & Truncate & VerticalAlign & ZIndex & GroupHover & { hover?: string } & Top & Right & Bottom & Left;

const getResponsivePropClasses = (prop: {[key: string]: string}, classPrefix: string) => {
const keys: string[] = Object.keys(prop)
Expand Down Expand Up @@ -209,6 +213,7 @@ const filterClassName = (value: string): string => {
// Prop categories
const PROP_CATEGORIES: {[key:string]: (props: {[key: string]: any}) => string} = {

groupHoverProps: ({ groupHover }: GroupHover ) => groupHover ? 'group_hover ' : '',
hoverProps: ({ hover }: { hover?: Hover }) => {
let css = '';
if (!hover) return css;
Expand Down
5 changes: 4 additions & 1 deletion playbook/lib/playbook/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Playbook
module Hover
def self.included(base)
base.prop :hover
base.prop :group_hover, type: Playbook::Props::Boolean, default: false
end

def hover_options
Expand Down Expand Up @@ -38,7 +39,8 @@ def hover_attributes

def hover_props
selected_props = hover_options.keys.select { |sk| try(sk) }
return nil unless selected_props.present?

return nil if selected_props.nil? && group_hover.nil?

responsive = selected_props.present? && try(selected_props.first).is_a?(::Hash)
css = ""
Expand All @@ -58,6 +60,7 @@ def hover_props
end
end

css += "group_hover " if group_hover
css.strip unless css.blank?
end
end
Expand Down

0 comments on commit 95eef34

Please sign in to comment.