Skip to content

Commit

Permalink
feat(Logo): allow color override (#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
pladaria and Pedro Ladaria authored Oct 8, 2024
1 parent e9e7067 commit 4d16939
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 42 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 27 additions & 3 deletions src/__screenshot_tests__/logo-screenshot-test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import {openStoryPage, screen} from '../test-utils';

const SKINS = ['Movistar', 'O2', 'O2-new', 'Vivo', 'Vivo-new', 'Telefonica', 'Blau', 'Tu'] as const;
import type {KnownSkinName} from '../skins/types';

const SKINS: Array<KnownSkinName> = [
'Movistar',
'O2',
'O2-new',
'Vivo',
'Vivo-new',
'Telefonica',
'Blau',
'Tu',
];
const LOGO_TYPES = ['imagotype', 'vertical', 'isotype'];
const INVERSE_VALUES = [false, true];
const DARK_MODE_VALUES = [false, true];
Expand Down Expand Up @@ -38,11 +49,24 @@ test.each(getBrandLogoCases())(
}
);

test.each(SKINS)('Logo. Default brand with skin={%s}', async (skin) => {
test.each(SKINS)('Logo. Default brand with skin={%s}', async (skin: KnownSkinName) => {
await openStoryPage({
id: 'components-logo--default',
device: 'DESKTOP',
skin: skin as (typeof SKINS)[number],
skin,
});

const story = await screen.findByTestId('logo');

const image = await story.screenshot();
expect(image).toMatchImageSnapshot();
});

test.each(SKINS)('Logo with color override skin=%s', async (skin: KnownSkinName) => {
await openStoryPage({
id: 'components-logo--default',
skin,
args: {color: '#000000', size: 64, type: 'imagotype'},
});

const story = await screen.findByTestId('logo');
Expand Down
24 changes: 22 additions & 2 deletions src/__stories__/logo-story.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as React from 'react';
import {BlauLogo, Logo, MovistarLogo, O2Logo, TelefonicaLogo, VivoLogo, TuLogo, O2NewLogo} from '../logo';
import {Box, ResponsiveLayout} from '../index';
import {Box, ResponsiveLayout, useTheme} from '../index';

const COLOR_OPTIONS = ['default', 'neutralHigh', 'neutralMedium', '#000000'] as const;

export default {
title: 'Components/Logo',
component: Logo,
parameters: {
fullScreen: true,
},
argTypes: {
color: {
options: COLOR_OPTIONS,
control: {type: 'select'},
},
},
};

type Args = {
Expand All @@ -17,6 +25,7 @@ type Args = {
action: 'none' | 'onPress' | 'href' | 'to';
forceBrandLogo: boolean;
brand: 'Movistar' | 'O2' | 'O2-new' | 'Vivo' | 'Telefonica' | 'Blau' | 'Tu';
color: (typeof COLOR_OPTIONS)[number];
};

const getLogoActionProps = (action: string) => {
Expand All @@ -42,11 +51,21 @@ const getLogoActionProps = (action: string) => {
: {};
};

export const Default: StoryComponent<Args> = ({type, size, inverse, action, forceBrandLogo, brand}) => {
export const Default: StoryComponent<Args> = ({
type,
size,
inverse,
action,
forceBrandLogo,
brand,
color,
}) => {
const {colorValues} = useTheme();
const logoProps = {
...getLogoActionProps(action),
type,
size,
color: color === 'default' ? undefined : colorValues[color as never] || color || undefined,
};

const CurrentLogo = {
Expand Down Expand Up @@ -78,6 +97,7 @@ Default.args = {
inverse: false,
forceBrandLogo: false,
brand: 'Movistar',
color: 'default',
};

Default.argTypes = {
Expand Down
12 changes: 9 additions & 3 deletions src/logo-blau.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const BlauLogoImage = ({size, type, isDarkMode, isInverse}: LogoImageProps): JSX.Element => {
const BlauLogoImage = ({
size,
type,
isDarkMode,
isInverse,
color: colorProp,
}: LogoImageProps): JSX.Element => {
const {colors} = getBlauSkin();
const color = isInverse && !isDarkMode ? colors.inverse : colors.brand;
const colorSecondary = isInverse && !isDarkMode ? colors.inverse : colors.promo;
const color = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.brand);
const colorSecondary = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.promo);

if (type === 'vertical') {
return (
Expand Down
1 change: 1 addition & 0 deletions src/logo-common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type LogoImageProps = {
type: LogoType;
isDarkMode: boolean;
isInverse: boolean;
color?: string;
};

export const calcInlineVars = (size: ByBreakpoint<number>): Record<string, string> => {
Expand Down
10 changes: 8 additions & 2 deletions src/logo-movistar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const MovistarLogoImage = ({size, type, isDarkMode, isInverse}: LogoImageProps): JSX.Element => {
const MovistarLogoImage = ({
size,
type,
isDarkMode,
isInverse,
color: colorProp,
}: LogoImageProps): JSX.Element => {
const {colors} = getMovistarSkin();
const color = isInverse && !isDarkMode ? colors.inverse : colors.brand;
const color = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.brand);

if (type === 'vertical') {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/logo-o2-new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const O2NewLogoImage = ({size, isDarkMode, isInverse}: LogoImageProps): JSX.Element => {
const O2NewLogoImage = ({size, isDarkMode, isInverse, color: colorProp}: LogoImageProps): JSX.Element => {
const {colors} = getO2NewSkin();
const color = isInverse && !isDarkMode ? colors.inverse : colors.brand;
const color = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.brand);

return (
<svg
Expand Down
4 changes: 2 additions & 2 deletions src/logo-o2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const O2LogoImage = ({size, isDarkMode, isInverse}: LogoImageProps): JSX.Element => {
const O2LogoImage = ({size, isDarkMode, isInverse, color: colorProp}: LogoImageProps): JSX.Element => {
const {colors} = getO2Skin();
const color = isInverse && !isDarkMode ? colors.inverse : colors.brand;
const color = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.brand);

return (
<svg
Expand Down
10 changes: 8 additions & 2 deletions src/logo-telefonica.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const TelefonicaLogoImage = ({size, type, isDarkMode, isInverse}: LogoImageProps): JSX.Element => {
const TelefonicaLogoImage = ({
size,
type,
isDarkMode,
isInverse,
color: colorProp,
}: LogoImageProps): JSX.Element => {
const {colors} = getTelefonicaSkin();
const color = isInverse && !isDarkMode ? colors.inverse : colors.brand;
const color = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.brand);

if (type === 'vertical') {
return (
Expand Down
5 changes: 3 additions & 2 deletions src/logo-tu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const TuLogoImage = ({size, isDarkMode, isInverse}: LogoImageProps): JSX.Element => {
const TuLogoImage = ({size, isDarkMode, isInverse, color: colorProp}: LogoImageProps): JSX.Element => {
const {colors} = getTuSkin();
const color = isDarkMode ? colors.inverse : isInverse ? colors.inverse : colors.backgroundBrand;
const color =
colorProp || (isDarkMode ? colors.inverse : isInverse ? colors.inverse : colors.backgroundBrand);

return (
<svg
Expand Down
10 changes: 8 additions & 2 deletions src/logo-vivo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {calcInlineVars} from './logo-common';

import type {LogoImageProps} from './logo-common';

const VivoLogoImage = ({size, type, isInverse, isDarkMode}: LogoImageProps): JSX.Element => {
const VivoLogoImage = ({
size,
type,
isInverse,
isDarkMode,
color: colorProp,
}: LogoImageProps): JSX.Element => {
const {colors} = getVivoSkin();
const color = isInverse && !isDarkMode ? colors.inverse : colors.brand;
const color = colorProp || (isInverse && !isDarkMode ? colors.inverse : colors.brand);

if (type === 'vertical') {
return (
Expand Down
Loading

1 comment on commit 4d16939

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-hhqb37tmg-flows-projects-65bb050e.vercel.app

Built with commit 4d16939.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.