aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/style/media.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-11-09 07:46:32 +0800
committerFabio Berger <me@fabioberger.com>2018-11-09 07:46:32 +0800
commiteb5f514d25e9392a9226cb778e94c5d7dd6e47f7 (patch)
tree40cc8c6d7481c01057d5c690f6423cc9938b27e5 /packages/instant/src/style/media.ts
parent57318a6ef22876a8c73321b7cc281302bbd67a3b (diff)
parent117e2f583ff44bdb63340a2134edea0f3ecb77b3 (diff)
downloaddexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.tar
dexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.tar.gz
dexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.tar.bz2
dexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.tar.lz
dexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.tar.xz
dexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.tar.zst
dexon-sol-tools-eb5f514d25e9392a9226cb778e94c5d7dd6e47f7.zip
Merge branch 'development' into fixOrderValidation
* development: (51 commits) [instant] Viewport specific errors (#1228) Added more comments Include wholeNumberSchema in sra-spec schemas chore(instant): fix linter Fix isNode fix(instant): update buy quote at start up in the case of default amount chore(instant): increase max bundle size for bundle watch Small code review tweaks fix: apply css reset to overlay as well fix(website): turn off production flag when building locally feat(instant): add Account to the ProviderState feat(instant): fallback to an empty wallet provider when none is injected [order_utils.py] is_signature_valid, via Exchange contract (#1216) chore: linter fix: progress bar fix: use fontSize prop in button feat: make instant resistant to external styles chore(instant): update OrderState enum to follow capitalization conventions feat: add faux externall css file Take out unneeded conditionals ...
Diffstat (limited to 'packages/instant/src/style/media.ts')
-rw-r--r--packages/instant/src/style/media.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/packages/instant/src/style/media.ts b/packages/instant/src/style/media.ts
new file mode 100644
index 000000000..5e7aaba37
--- /dev/null
+++ b/packages/instant/src/style/media.ts
@@ -0,0 +1,51 @@
+import { InterpolationValue } from 'styled-components';
+
+import { css } from './theme';
+
+export enum ScreenWidths {
+ Sm = 40,
+ Md = 52,
+ Lg = 64,
+}
+
+const generateMediaWrapper = (screenWidth: ScreenWidths) => (...args: any[]) => css`
+ @media (max-width: ${screenWidth}em) {
+ ${css.apply(css, args)};
+ }
+`;
+
+export const media = {
+ small: generateMediaWrapper(ScreenWidths.Sm),
+ medium: generateMediaWrapper(ScreenWidths.Md),
+ large: generateMediaWrapper(ScreenWidths.Lg),
+};
+
+export interface ScreenSpecification<T> {
+ default: T;
+ sm?: T;
+ md?: T;
+ lg?: T;
+}
+export type OptionallyScreenSpecific<T> = T | ScreenSpecification<T>;
+export type MediaChoice = OptionallyScreenSpecific<string>;
+/**
+ * Given a css property name and a OptionallyScreenSpecific value,
+ * generates css properties with screen-specific viewport styling
+ */
+export function stylesForMedia<T extends string | number>(
+ cssPropertyName: string,
+ choice: OptionallyScreenSpecific<T>,
+): InterpolationValue[] {
+ if (typeof choice === 'object') {
+ return css`
+ ${cssPropertyName}: ${choice.default};
+ ${choice.lg && media.large`${cssPropertyName}: ${choice.lg}`}
+ ${choice.md && media.medium`${cssPropertyName}: ${choice.md}`}
+ ${choice.sm && media.small`${cssPropertyName}: ${choice.sm}`}
+ `;
+ } else {
+ return css`
+ ${cssPropertyName}: ${choice};
+ `;
+ }
+}