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

[PLAY-1587] Group hover Global Prop #3833

Merged
merged 9 commits into from
Nov 7, 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
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
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
Loading