Skip to content

Commit

Permalink
feat(input): input mobile theme (PDS-241) (#737)
Browse files Browse the repository at this point in the history
* feat: add mobile theme for form-contro & input

* chore(input): screenshots

* chore: update mobile button screenshots

Co-authored-by: dmitrsavk <dmitrsavk@yandex.ru>
  • Loading branch information
reme3d2y and dmitrsavk committed Jul 23, 2021
1 parent f5cf284 commit 88f6f7c
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 49 deletions.
23 changes: 23 additions & 0 deletions .storybook/addons/theme-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@ import { useEffect, useCallback } from 'react';
import addons, { makeDecorator } from '@storybook/addons';
import { ADDON_ID, THEME_DATA_ATTR } from './register';

// Создает style-тэг с bluetint цветами для мобильной темы
const handleThemeColors = theme => {
const tagId = 'mobile-styles';

const existingStyleTag = document.getElementById(tagId);

if (theme === 'mobile' && !existingStyleTag) {
import(`!!raw-loader!../../../packages/vars/src/colors-bluetint.css`).then(module => {
const style = document.createElement('style');
style.id = 'mobile-styles';
style.innerHTML = module.default;

document.head.appendChild(style);
});
}

if (theme !== 'mobile' && existingStyleTag) {
existingStyleTag.remove();
}
};

export default makeDecorator({
name: 'withThemeSwitcher',
wrapper: (getStory, context) => {
const channel = addons.getChannel();

const setTheme = useCallback(theme => {
document.body.dataset[THEME_DATA_ATTR] = theme;

handleThemeColors(theme);
}, []);

useEffect(() => {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/form-control/src/docs/Component.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styles from '!!raw-loader!../index.module.css';
<Meta
title='Компоненты/FormControl'
component={FormControl}
parameters={{ 'theme-switcher': { themes: ['click'] } }}
parameters={{ 'theme-switcher': { themes: ['click', 'mobile'] } }}
/>


Expand Down
2 changes: 2 additions & 0 deletions packages/form-control/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
--form-control-labeled-m-paddings: 28px var(--gap-s) 8px;
--form-control-labeled-l-paddings: 34px var(--gap-m) 10px;
--form-control-labeled-xl-paddings: 38px var(--gap-m) 14px;
--form-control-sub-paddings: 0;

/* disabled */
--form-control-disabled-bg-color: color-mod(var(--color-light-bg-primary-inverted) alpha(15%));
Expand Down Expand Up @@ -136,6 +137,7 @@

display: block;
margin-top: var(--gap-2xs);
padding: var(--form-control-sub-paddings);
}

.hint {
Expand Down
1 change: 1 addition & 0 deletions packages/input/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
className={cn(
styles.input,
{
[styles.error]: error,
[styles.hasLabel]: label,
},
inputClassName,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 51 additions & 45 deletions packages/input/src/component.screenshots.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,60 @@ const screenshotTesting = setupScreenshotTesting({

const clip = { x: 0, y: 0, width: 350, height: 150 };

describe(
'Input | screenshots main props',
screenshotTesting({
cases: [
[
'sprite',
createSpriteStorybookUrl({
componentName: 'Input',
knobs: {
label: 'Label',
size: ['s', 'm', 'l'],
block: [false, true],
disabled: [false, true],
value: ['', 'Value'],
},
size: { width: 350, height: 150 },
}),
describe('Input | screenshots main props', () => {
const testCase = (theme: string) =>
screenshotTesting({
cases: [
[
`${theme} theme`,
createSpriteStorybookUrl({
componentName: 'Input',
knobs: {
label: 'Label',
size: ['s', 'm', 'l'],
block: [false, true],
disabled: [false, true],
value: ['', 'Value'],
},
size: { width: 350, height: 150 },
}),
],
],
],
screenshotOpts: {
fullPage: true,
},
}),
);
screenshotOpts: {
fullPage: true,
},
theme,
})();

describe(
'Input | screenshots hint and error',
screenshotTesting({
cases: [
[
'sprite',
createSpriteStorybookUrl({
componentName: 'Input',
knobs: {
size: 'm',
hint: ['', 'Hint'],
error: ['', 'Error'],
value: ['', 'Value'],
},
size: { width: 350, height: 150 },
}),
['default', 'click', 'site', 'mobile'].map(testCase);
});

describe('Input | screenshots hint and error', () => {
const testCase = (theme: string) =>
screenshotTesting({
cases: [
[
`${theme} theme`,
createSpriteStorybookUrl({
componentName: 'Input',
knobs: {
size: 'm',
hint: ['', 'Hint'],
error: ['', 'Error'],
value: ['', 'Value'],
},
size: { width: 350, height: 150 },
}),
],
],
],
screenshotOpts: {
fullPage: true,
},
}),
);
screenshotOpts: {
fullPage: true,
},
theme,
})();

['default', 'click', 'site', 'mobile'].map(testCase);
});

describe(
'Input | screenshots addons',
Expand Down
2 changes: 1 addition & 1 deletion packages/input/src/docs/Component.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styles from '!!raw-loader!../index.module.css';
<Meta
title='Компоненты/Input'
component={Input}
parameters={{ 'theme-switcher': { themes: ['click', 'site'] } }}
parameters={{ 'theme-switcher': { themes: ['click', 'site', 'mobile'] } }}
/>


Expand Down
11 changes: 11 additions & 0 deletions packages/input/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
--input-success-icon-display: flex;
--input-error-icon: url('https://alfabank.st/icons/glyph_alert-circle_m_negative.svg');
--input-success-icon: url('https://alfabank.st/icons/icon_ok_s_color.svg');
--input-caret-color: var(--input-color);

/* disabled */
--input-disabled-color: var(--color-light-text-secondary);

/* read-only */
--input-read-only-color: var(--color-light-text-secondary);

/* error */
--input-error-color: var(--color-light-text-primary);
}

@define-mixin _input-icon {
Expand All @@ -39,6 +43,7 @@
outline: none;
text-overflow: ellipsis;
box-sizing: border-box;
caret-color: var(--input-caret-color);
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
Expand Down Expand Up @@ -124,6 +129,12 @@
opacity: 0;
}

/* ERROR STATE */
.error {
color: var(--input-error-color);
caret-color: var(--input-error-color);
}

/* IE hide clear */

.input::-ms-clear {
Expand Down
31 changes: 31 additions & 0 deletions packages/themes/src/mixins/form-control/mobile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import '../../../../themes/src/default.css';

@define-mixin form-control-mobile {
/* core vars */
--color-light-bg-secondary: #f3f4f5;
--border-radius-l: 12px;

/* theme */
--form-control-border-radius: var(--border-radius-l);
--form-control-border-bottom: 0;
--form-control-bg-color: var(--color-light-bg-secondary);

/* disabled */
--form-control-disabled-opacity: 0.5;
--form-control-disabled-border-bottom: 0;
--form-control-disabled-bg-color: var(--color-light-bg-secondary);

/* focus */
--form-control-focus-shadow: none;
--form-control-focus-border-bottom: 0;
--form-control-focus-bg-color: var(--color-light-bg-secondary);
--form-control-hover-bg-color: var(--color-light-bg-secondary);

/* error */
--form-control-error-label-color: var(--form-control-error-color);
--form-control-error-shadow: none;
--form-control-error-border-bottom: 0;

/* paddings */
--form-control-sub-paddings: 0 var(--gap-2xs);
}
16 changes: 16 additions & 0 deletions packages/themes/src/mixins/input/mobile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import '../../../../themes/src/default.css';

@define-mixin input-mobile {
/* core vars */
--color-light-text-primary: #000;
--color-light-text-negative: #d91d0b;
--color-light-text-tertiary-transparent: rgba(60, 60, 67, 0.3);
--color-light-text-link: #0072ef;

/* theme */
--input-error-color: var(--color-light-text-negative);
--input-error-icon-display: none;
--input-disabled-color: var(--color-light-text-primary);
--input-focus-placeholder-color: var(--color-light-text-tertiary-transparent);
--input-caret-color: var(--color-light-text-link);
}
4 changes: 4 additions & 0 deletions packages/themes/src/mixins/mobile.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import './button/mobile.css';
@import './form-control/mobile.css';
@import './input/mobile.css';
@import './tag/mobile.css';
@import './checkbox/mobile.css';
@import './radio/mobile.css';
Expand All @@ -10,4 +12,6 @@
@mixin checkbox-mobile;
@mixin radio-mobile;
@mixin confirmation-mobile;
@mixin form-control-mobile;
@mixin input-mobile;
}

0 comments on commit 88f6f7c

Please sign in to comment.