Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Telefonica/mistica-web into WEB-1990
Browse files Browse the repository at this point in the history
-rename-design-tokens
  • Loading branch information
marcoskolodny committed Sep 12, 2024
2 parents 5c595e6 + 3808b4f commit 201cba7
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 434 deletions.
2 changes: 1 addition & 1 deletion playroom/snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const buttonSnippets: Array<Snippet> = [
code: '<ButtonPrimary onPress={() => {}}><IconLockClosedRegular color="currentColor" />Action</ButtonPrimary>',
},
{
name: 'ButtonGroup (internal use)',
name: 'ButtonGroup',
code: `
<ButtonGroup
primaryButton={<ButtonPrimary onPress={() => {}}>Action</ButtonPrimary>}
Expand Down
12 changes: 3 additions & 9 deletions src/__acceptance_tests__/__ssr_pages__/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ import {
MainSectionHeader,
ButtonPrimary,
Stack,
Placeholder,
} from '../../..';

const HeaderTest = (): JSX.Element => (
<Stack space={8}>
<HeaderLayout
header={
<Header
title="La última factura de diciembre ya esta disponible"
preamount="Cuota mensual (IVA incluido)"
amount="60,44 €"
button={<ButtonPrimary href="asdf">Descargar factura</ButtonPrimary>}
subtitle="Y esto es un subtitulo"
/>
}
header={<Header title="La última factura de diciembre ya esta disponible" />}
extra={<Placeholder />}
/>
<MainSectionHeaderLayout>
<MainSectionHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Default: StoryComponent<Args> = ({largeContent, input}) => {
{() => (
<>
<MainNavigationBar
isInverse
variant="inverse"
sections={['Start', 'Account', 'Explore', 'Support'].map((title, index) => ({
title,
onPress: () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__stories__/fixed-footer-layout-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ResponsiveLayout,
Box,
Inline,
alert,
useDialog,
} from '..';
import {useCheckbox} from './helpers';

Expand Down Expand Up @@ -100,6 +100,7 @@ MoreComplexFooter.storyName = 'Fixed footer layout';
MoreComplexFooter.parameters = {fullScreen: true};

export const DialogOverFixedFooter: StoryComponent = () => {
const {alert} = useDialog();
return (
<ButtonFixedFooterLayout
button={<ButtonPrimary onPress={() => alert({message: 'Message'})}>Open dialog</ButtonPrimary>}
Expand Down
3 changes: 2 additions & 1 deletion src/__stories__/form-automatic-state-management-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Switch,
Checkbox,
TextLink,
alert,
useDialog,
RadioGroup,
RadioButton,
Text3,
Expand All @@ -39,6 +39,7 @@ const fruitOptions = fruitEntries.map(([text, value]) => ({text, value}));
const countryOptions = countriesList.map((text, i) => ({text, value: '' + i}));

export const Default: StoryComponent = () => {
const {alert} = useDialog();
return (
<Form
initialValues={{
Expand Down
3 changes: 2 additions & 1 deletion src/__stories__/menu-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
MenuItem,
IconLightningRegular,
MenuSection,
alert,
useDialog,
} from '..';

export default {
Expand All @@ -34,6 +34,7 @@ export const Default: StoryComponent<MenuArgs> = ({
icon,
checkbox,
}) => {
const {alert} = useDialog();
const [valuesState, setValuesState] = React.useState<ReadonlyArray<number>>([]);

const setValues = (val: number) => {
Expand Down
3 changes: 2 additions & 1 deletion src/__stories__/use-modal-state-story.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import {useModalState, Stack, Text2, alert} from '..';
import {useModalState, Stack, Text2, useDialog} from '..';
import {ButtonPrimary} from '../button';

export default {
Expand All @@ -8,6 +8,7 @@ export default {

export const UseModalState: StoryComponent = () => {
const {isModalOpen} = useModalState();
const {alert} = useDialog();
return (
<div aria-hidden={isModalOpen}>
<Stack space={32}>
Expand Down
2 changes: 0 additions & 2 deletions src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ interface AccordionItemContentProps {
dataAttributes?: DataAttributes;
trackingEvent?: TrackingEvent | ReadonlyArray<TrackingEvent>;
role?: string;
/** @deprecated Use onChange Accordion's onChange callback instead */
onToogle?: (value: boolean) => void;
}

const useAccordionState = ({
Expand Down
10 changes: 1 addition & 9 deletions src/button-fixed-footer-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use client';
import * as React from 'react';
import FixedFooterLayout from './fixed-footer-layout';
import ButtonLayout from './button-layout';
import {useScreenSize} from './hooks';
import {InternalResponsiveLayout} from './responsive-layout';
import Box from './box';

Expand All @@ -12,8 +10,6 @@ import type {RendersNullableElement} from './utils/types';
type Props = {
isFooterVisible?: boolean;
button?: NullableButtonElement;
/** @deprecated */
desktopButtonAlign?: 'left' | 'center';
secondaryButton?: NullableButtonElement;
link?: RendersNullableElement<typeof ButtonLink>;
footerBgColor?: string;
Expand All @@ -28,12 +24,10 @@ const ButtonFixedFooterLayout = ({
secondaryButton,
link,
children,
desktopButtonAlign,
footerBgColor,
containerBgColor,
onChangeFooterHeight,
}: Props): JSX.Element => {
const {isDesktopOrBigger} = useScreenSize();
const hasButton = !!button || !!secondaryButton;
return (
<FixedFooterLayout
Expand All @@ -53,9 +47,7 @@ const ButtonFixedFooterLayout = ({
<ButtonLayout
primaryButton={button}
secondaryButton={secondaryButton}
align={
isDesktopOrBigger && desktopButtonAlign ? desktopButtonAlign : 'full-width'
}
align="full-width"
link={link}
/>
</Box>
Expand Down
12 changes: 0 additions & 12 deletions src/button-layout.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ import {buttonPaddingX, borderSize} from './button.css';

const buttonLayoutSpacing = 16;

export const margins = style({
margin: '16px 0',
padding: '0 16px',

'@media': {
[mq.tabletOrSmaller]: {
padding: 0,
margin: 16,
},
},
});

export const container = style([
sprinkles({display: 'flex', alignItems: 'center'}),
{
Expand Down
52 changes: 15 additions & 37 deletions src/button-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,41 @@
'use client';
import * as React from 'react';
import {ButtonPrimary, ButtonSecondary, ButtonDanger} from './button';
import classnames from 'classnames';
import {getPrefixedDataAttributes} from './utils/dom';
import * as styles from './button-layout.css';

import type {ButtonPrimary, ButtonSecondary, ButtonDanger, ButtonLink} from './button';
import type {DataAttributes, RendersNullableElement} from './utils/types';
import type {NullableButtonElement, ButtonLink} from './button';

type MaybeButtonElement = NullableButtonElement | void | false;

type ButtonLayoutProps = {
/** @deprecated Use primaryButton and secondaryButton props */
children?: MaybeButtonElement | [MaybeButtonElement, MaybeButtonElement];
align?: 'center' | 'left' | 'right' | 'full-width';
primaryButton?: RendersNullableElement<typeof ButtonPrimary | typeof ButtonDanger>;
secondaryButton?: RendersNullableElement<typeof ButtonSecondary>;
link?: RendersNullableElement<typeof ButtonLink>;
/** @deprecated Use a wrapping Box if you need paddings */
withMargins?: boolean;
dataAttributes?: DataAttributes;
};

const buttonsRange = [ButtonPrimary, ButtonDanger, ButtonSecondary];

const ButtonLayout = ({
children,
primaryButton,
secondaryButton,
align = 'full-width',
link,
withMargins = false,
dataAttributes,
}: ButtonLayoutProps): JSX.Element => {
const sortedButtons = React.Children.toArray(children as any).sort((b1: any, b2: any) => {
const range1 = buttonsRange.indexOf(b1.type);
const range2 = buttonsRange.indexOf(b2.type);
return align === 'right' ? range2 - range1 : range1 - range2;
});
const numberOfButtons = (primaryButton ? 1 : 0) + (secondaryButton ? 1 : 0);

const numberOfButtons = children
? sortedButtons.length
: (primaryButton ? 1 : 0) + (secondaryButton ? 1 : 0);

const buttons = children ? (
sortedButtons
) : align === 'right' ? (
<>
{secondaryButton}
{primaryButton}
</>
) : (
<>
{primaryButton}
{secondaryButton}
</>
);
const buttons =
align === 'right' ? (
<>
{secondaryButton}
{primaryButton}
</>
) : (
<>
{primaryButton}
{secondaryButton}
</>
);

const linkContainer = link ? (
<div
Expand All @@ -66,7 +46,7 @@ const ButtonLayout = ({
</div>
) : null;

const content = (
return (
<div
className={classnames(styles.container, styles.alignVariant[align], {
[styles.containerWithTwoButtons]: numberOfButtons > 1,
Expand All @@ -86,8 +66,6 @@ const ButtonLayout = ({
)}
</div>
);

return withMargins ? <div className={styles.margins}>{content}</div> : content;
};

export default ButtonLayout;
5 changes: 1 addition & 4 deletions src/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1461,8 +1461,6 @@ export const DisplayDataCard = React.forwardRef<HTMLDivElement, DisplayDataCardP
);

interface PosterCardBaseProps {
/** @deprecated use aria-label */
ariaLabel?: string;
'aria-label'?: string;
aspectRatio?: AspectRatio | number;
width?: number | string;
Expand Down Expand Up @@ -1521,8 +1519,7 @@ export const PosterCard = React.forwardRef<HTMLDivElement, PosterCardProps>(
width,
height,
aspectRatio = '7:10',
ariaLabel: deprecatedAriaLabel,
['aria-label']: ariaLabelProp = deprecatedAriaLabel,
'aria-label': ariaLabelProp,
actions,
onClose,
closeButtonLabel,
Expand Down
7 changes: 5 additions & 2 deletions src/community/__stories__/blocks-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ValueBlock,
} from '../blocks';
import imgExample from '../../__stories__/images/avatar.jpg';
import {vars} from '../../skins/skin-contract.css';

import type {TagType} from '../..';

Expand Down Expand Up @@ -146,8 +147,10 @@ export const BlockHighlightedValue: StoryComponent<HighlightedValueBlockArgs> =
headline={<Tag type={headlineType}>{headline}</Tag>}
title={title}
description={description}
mainHeading={{value, text}}
secondaryValue={secondaryValue}
headings={[
{value, text},
{value: secondaryValue, valueColor: vars.colors.textSecondary},
]}
/>
</Box>
</ResponsiveLayout>
Expand Down
49 changes: 5 additions & 44 deletions src/community/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,49 +143,26 @@ interface Heading {

interface HighlightedValueBlockProps {
headline?: RendersNullableElement<typeof Tag>;

headings?: ReadonlyArray<Heading>;

/** @deprecated Use headings instead */
mainHeading?: {
value: string;
text: string;
};

/** @deprecated Use headings instead */
secondHeading?: {
value: string;
text: string;
};

/** @deprecated Use headings instead */
secondaryValue?: string;

title?: string;
description?: ReadonlyArray<string> | string;
/** @deprecated Use headings instead */
valueColor?: string;
'aria-label'?: string;
}

export const HighlightedValueBlock = ({
headline,
headings,
mainHeading,
secondHeading,
secondaryValue,
title,
description,
valueColor = vars.colors.textPrimary,
'aria-label': ariaLabel,
}: HighlightedValueBlockProps): JSX.Element => {
return (
<div aria-label={ariaLabel}>
{headline && <Box paddingBottom={24}>{headline}</Box>}

<Stack space={2}>
{headings &&
headings.map((heading, index) => (
{headings && (
<Stack space={2}>
{headings.map((heading, index) => (
<Inline key={index} space={8} alignItems="baseline">
<Text8 color={heading.valueColor ?? vars.colors.textPrimary}>
{heading.value}
Expand All @@ -195,24 +172,8 @@ export const HighlightedValueBlock = ({
</Text2>
</Inline>
))}
{mainHeading && (
<Inline space={8} alignItems="baseline">
<Text8 color={valueColor}>{mainHeading.value}</Text8>
<Text2 regular color={vars.colors.textSecondary}>
{mainHeading.text}
</Text2>
</Inline>
)}
{secondHeading && (
<Inline space={8} alignItems="baseline">
<Text8 color={valueColor}>{secondHeading.value}</Text8>
<Text2 regular color={vars.colors.textSecondary}>
{secondHeading.text}
</Text2>
</Inline>
)}
{secondaryValue && <Text8 color={vars.colors.textSecondary}>{secondaryValue}</Text8>}
</Stack>
</Stack>
)}
{title || description ? (
<Box paddingTop={8}>
<BlockContent title={title} description={description} />
Expand Down
Loading

0 comments on commit 201cba7

Please sign in to comment.