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

fix: update styles on color page #4157

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -12,8 +12,7 @@ export const GdprBanner = () => {
setBannerOpen(false);
}

// return !isBannerOpen ? null : (
return (
return !isBannerOpen ? null : (
<Flex className="ws-gdpr-banner-container">
<Panel variant="bordered" className="pf-m-raised" id="ws-gdpr-banner">
<PanelMain>
Expand Down
2 changes: 1 addition & 1 deletion packages/documentation-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"screenshots": "pf-docs-framework screenshots"
},
"dependencies": {
"@patternfly/documentation-framework": "6.0.0-alpha.68",
"@patternfly/documentation-framework": "6.0.0-alpha.69",
"@patternfly/react-catalog-view-extension": "6.0.0-alpha.4",
"@patternfly/react-console": "6.0.0-alpha.4",
"@patternfly/react-docs": "7.0.0-alpha.102",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tokens from '@patternfly/react-tokens/dist/esm/patternfly_variables';
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
import { css } from '@patternfly/react-styles';
import { normalizeColor, getContrastRatio } from './helpers';
import './ColorFamily.css';
import { Accordion, AccordionItem, AccordionContent, AccordionToggle, Content, ContentVariants, Title } from '@patternfly/react-core';

const palettePrefix = '--pf-t--color--';

Expand All @@ -14,22 +14,14 @@ export function ColorFamily({
const [expanded, setExpanded] = React.useState([]);
const rootTokens = tokens[':where(:root)'];

const familyTokens = family === 'shadows'
? [rootTokens.global_box_shadow_sm, rootTokens.global_box_shadow_md, rootTokens.global_box_shadow_lg]
: Object.values(rootTokens).filter(token => token.name.includes(`${palettePrefix}${family}`));
if (family === 'black') {
const whiteToken = rootTokens.color_white
const familyTokens = Object.values(rootTokens).filter(token => token.name.includes(`${palettePrefix}${family}--`));
if (family === 'gray') {
const whiteToken = rootTokens.color_white;
familyTokens.unshift(whiteToken);
const blackToken = rootTokens.color_black;
familyTokens.push(blackToken);
}

const expandAll = () => {
if (expanded.length > 0) {
setExpanded([]);
} else {
setExpanded(familyTokens.map(token => token.name));
}
};

const expand = name => {
if (expanded.includes(name)) {
setExpanded(expanded.filter(token => token !== name));
Expand All @@ -40,92 +32,57 @@ export function ColorFamily({

return (
<React.Fragment>
<dl className="pf-v6-c-accordion pf-v6-u-p-0">
<dt
className={css(
'pf-v6-c-accordion__toggle',
'ws-color-family-accordion-toggle',
expanded.length === familyTokens.length && 'pf-m-expanded'
)}
onClick={expandAll}
>
<h3 className="pf-v6-c-title pf-m-xl">
<AngleRightIcon className="pf-v6-c-accordion__toggle-icon ws-color-family-toggle-icon" />
{title}
</h3>
</dt>
<Title headingLevel="h3">{title}</Title>
<Accordion togglePosition="start">
{familyTokens.map(token => {
const isExpanded = expanded.includes(token.name);
const isShadows = family === 'shadows';
const tokenClass = css(
'pf-v6-c-accordion__toggle',
'ws-color-family-toggle',
isExpanded && 'pf-m-expanded'
);
const itemStyle = {
background: `var(${token.name})`,
// fontSize: 'var(--pf-v6-global--FontSize--sm)'
'--pf-v6-c-accordion__toggle--BackgroundColor': `var(${token.name})`,
'--pf-v6-c-accordion__toggle--hover--BackgroundColor': `var(${token.name})`,
fontSize: 'var(--pf-t--global--font--size--md)'
};
if (isShadows) {
itemStyle.marginBottom = '1rem';
itemStyle.boxShadow = `var(${token.name})`;
if (getContrastRatio(token.value, '#151515') > 4.5) {
itemStyle['--pf-v6-c-accordion__toggle-text--Color'] = '#151515';
}
else if (getContrastRatio(token.value, '#151515') <= 4.5) {
itemStyle.color = 'var(--pf-v6-global--Color--light-100)';
}
else if (getContrastRatio(token.value, '#151515') > 4.5) {
itemStyle.color = 'var(--pf-v6-global--palette--black-900)';
}
const expandedStyle = {};
if (isExpanded && !isShadows) {
const borderLeftWidth = 'var(--pf-v6-c-accordion__toggle--m-expanded--BorderWidth)';
const borderColor = `var(${token.name})`;
const borderStyle = 'solid';
itemStyle.borderLeftWidth = borderLeftWidth;
itemStyle.borderColor = borderColor;
itemStyle.borderStyle = borderStyle;
expandedStyle.borderLeftWidth = borderLeftWidth;
expandedStyle.borderColor = borderColor;
expandedStyle.borderStyle = borderStyle;
itemStyle['--pf-v6-c-accordion__toggle-text--Color'] = '#FFFFFF';
}

const tokenList = Object.values(rootTokens)
.filter(t => t.value === token.value && !/\d/.test(t.name)) // only show semantic tokens (without digits at the end)
.map(t => t.name)
.sort();

return (
<React.Fragment key={token.name}>
<dd
className={`${tokenClass} ws-color-family-accordion-toggle`}
style={itemStyle}
<AccordionItem isExpanded={isExpanded} style={itemStyle}>
<AccordionToggle
onClick={() => expand(token.name)}
// id={!isShadows ? token.value.replace('#', 'color-') : token.name.replace('--pf-v6-global--BoxShadow--', '')}
id={token.value.replace('#', 'color-')}
style={{
backgroundColor: `${token.value} !important`,
color: itemStyle['--pf-v6-c-accordion__toggle-text--Color']
}}
>
<div>
<AngleRightIcon className="pf-v6-c-accordion__toggle-icon ws-color-family-toggle-icon" />
{token.name
.replace(palettePrefix, '')
// .replace('--pf-v6-global--BoxShadow--', 'box shadow ')}
}
</div>
{!isShadows && (
<div className="ws-color-family-color">
#{normalizeColor(token.value.toUpperCase())}
</div>
#{normalizeColor(token.value.toUpperCase())}
</AccordionToggle>
<AccordionContent>
{tokenList?.length > 0 ? (
<>
<Title headingLevel="h4" size="md">Semantic tokens<span className='pf-v6-screen-reader'>for {token.value.toUpperCase()}</span></Title>
<Content className="pf-v6-u-m-sm" component={ContentVariants.ol} isPlainList>
{tokenList.map(tokenName =>
<Content component={ContentVariants.li} key={tokenName}>{tokenName}</Content>
)}
</Content>
</>
) : (
<Title headingLevel="h4" size="md">No semantic tokens<span className='pf-v6-screen-reader'>for {token.value.toUpperCase()}</span></Title>
)}
</dd>
{isExpanded && (
<dd className={`${tokenClass} ws-color-family-content`} style={expandedStyle}>
<label className="ws-color-family-label">Tokens</label>
{Object.values(rootTokens)
.filter(t => t.value === token.value)
.map(t => t.name)
.sort()
.map(tokenName =>
<div key={tokenName}>{tokenName}</div>
)}
</dd>
)}
</React.Fragment>
</AccordionContent>
</AccordionItem>
);
})}
</dl>
</Accordion>
</React.Fragment>
);
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
.ws-color-swatch {
display: flex;
margin-bottom: var(--pf-t--global--spacer--lg);
}

.ws-color-swatch > svg {
flex: 0 0 44px;
margin-right: var(--pf-t--global--spacer--md);
border-radius: 50%;
}

.ws-color-swatch > svg:hover {
cursor: pointer;
box-shadow: var(--pf-t--global--box-shadow--lg);
/* box-shadow: 0 0 0 0.0625rem rgba(3, 3, 3, 0.05), 0 0.25rem 0.5rem 0.25rem rgba(3, 3, 3, 0.06); */
}

.ws-color-swatch-description {
display: flex;
flex-direction: column;
align-content: space-between;
}

.ws-color-swatch-description-label {
font-size: var(--pf-t--global--font--size--sm);
font-weight: var(--pf-t--global--font--weight--body--bold);
margin-bottom: var(--pf-t--global--spacer--xs);
}

.ws-color-swatch-popover {
font-size: var(--pf-t--global--font--size--sm);
}

.ws-color-swatch-popover-label {
display: inline-block;
padding-top: var(--pf-t--global--spacer--md);
padding-bottom: var(--pf-t--global--spacer-sm);
font-weight: bold;
}

.ws-color-swatch-popover-code {
margin-bottom: var(--pf-t--global--spacer--sm);
}

.ws-color-swatch-usage {
max-width: 25rem;
display: inline-block;
word-wrap: break-word;
}

.ws-color-swatch-image{
margin-right: var(--pf-t--global--spacer--md);
}
Loading
Loading