diff --git a/fonts/OFL.txt b/fonts/OFL.txt new file mode 100644 index 0000000..a417551 --- /dev/null +++ b/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2011 The Roboto Project Authors (https://github.com/googlefonts/roboto-classic) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fonts/README.txt b/fonts/README.txt new file mode 100644 index 0000000..26368fa --- /dev/null +++ b/fonts/README.txt @@ -0,0 +1,118 @@ +Roboto Variable Font +==================== + +This download contains Roboto as both variable fonts and static fonts. + +Roboto is a variable font with these axes: + wdth + wght + +This means all the styles are contained in these files: + Roboto-VariableFont_wdth,wght.ttf + Roboto-Italic-VariableFont_wdth,wght.ttf + +If your app fully supports variable fonts, you can now pick intermediate styles +that aren’t available as static fonts. Not all apps support variable fonts, and +in those cases you can use the static font files for Roboto: + static/Roboto_Condensed-Thin.ttf + static/Roboto_Condensed-ExtraLight.ttf + static/Roboto_Condensed-Light.ttf + static/Roboto_Condensed-Regular.ttf + static/Roboto_Condensed-Medium.ttf + static/Roboto_Condensed-SemiBold.ttf + static/Roboto_Condensed-Bold.ttf + static/Roboto_Condensed-ExtraBold.ttf + static/Roboto_Condensed-Black.ttf + static/Roboto_SemiCondensed-Thin.ttf + static/Roboto_SemiCondensed-ExtraLight.ttf + static/Roboto_SemiCondensed-Light.ttf + static/Roboto_SemiCondensed-Regular.ttf + static/Roboto_SemiCondensed-Medium.ttf + static/Roboto_SemiCondensed-SemiBold.ttf + static/Roboto_SemiCondensed-Bold.ttf + static/Roboto_SemiCondensed-ExtraBold.ttf + static/Roboto_SemiCondensed-Black.ttf + static/Roboto-Thin.ttf + static/Roboto-ExtraLight.ttf + static/Roboto-Light.ttf + static/Roboto-Regular.ttf + static/Roboto-Medium.ttf + static/Roboto-SemiBold.ttf + static/Roboto-Bold.ttf + static/Roboto-ExtraBold.ttf + static/Roboto-Black.ttf + static/Roboto_Condensed-ThinItalic.ttf + static/Roboto_Condensed-ExtraLightItalic.ttf + static/Roboto_Condensed-LightItalic.ttf + static/Roboto_Condensed-Italic.ttf + static/Roboto_Condensed-MediumItalic.ttf + static/Roboto_Condensed-SemiBoldItalic.ttf + static/Roboto_Condensed-BoldItalic.ttf + static/Roboto_Condensed-ExtraBoldItalic.ttf + static/Roboto_Condensed-BlackItalic.ttf + static/Roboto_SemiCondensed-ThinItalic.ttf + static/Roboto_SemiCondensed-ExtraLightItalic.ttf + static/Roboto_SemiCondensed-LightItalic.ttf + static/Roboto_SemiCondensed-Italic.ttf + static/Roboto_SemiCondensed-MediumItalic.ttf + static/Roboto_SemiCondensed-SemiBoldItalic.ttf + static/Roboto_SemiCondensed-BoldItalic.ttf + static/Roboto_SemiCondensed-ExtraBoldItalic.ttf + static/Roboto_SemiCondensed-BlackItalic.ttf + static/Roboto-ThinItalic.ttf + static/Roboto-ExtraLightItalic.ttf + static/Roboto-LightItalic.ttf + static/Roboto-Italic.ttf + static/Roboto-MediumItalic.ttf + static/Roboto-SemiBoldItalic.ttf + static/Roboto-BoldItalic.ttf + static/Roboto-ExtraBoldItalic.ttf + static/Roboto-BlackItalic.ttf + +Get started +----------- + +1. Install the font files you want to use + +2. Use your app's font picker to view the font family and all the +available styles + +Learn more about variable fonts +------------------------------- + + https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts + https://variablefonts.typenetwork.com + https://medium.com/variable-fonts + +In desktop apps + + https://theblog.adobe.com/can-variable-fonts-illustrator-cc + https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts + +Online + + https://developers.google.com/fonts/docs/getting_started + https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide + https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts + +Installing fonts + + MacOS: https://support.apple.com/en-us/HT201749 + Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux + Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows + +Android Apps + + https://developers.google.com/fonts/docs/android + https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts + +License +------- +Please read the full license text (OFL.txt) to understand the permissions, +restrictions and requirements for usage, redistribution, and modification. + +You can use them in your products & projects – print or digital, +commercial or otherwise. + +This isn't legal advice, please consider consulting a lawyer and see the full +license for all details. diff --git a/fonts/roboto.css b/fonts/roboto.css new file mode 100644 index 0000000..f01ea02 --- /dev/null +++ b/fonts/roboto.css @@ -0,0 +1,4 @@ +@font-face { + font-family: 'Roboto Flex'; + src: url('fonts/roboto.ttf') format('truetype'); +} \ No newline at end of file diff --git a/fonts/roboto.ttf b/fonts/roboto.ttf new file mode 100644 index 0000000..bba55f6 Binary files /dev/null and b/fonts/roboto.ttf differ diff --git a/fonts/roboto_italic.ttf b/fonts/roboto_italic.ttf new file mode 100644 index 0000000..978e53a Binary files /dev/null and b/fonts/roboto_italic.ttf differ diff --git a/src/components/Forms.tsx b/src/components/Forms.tsx index c5acf7a..44ebab0 100644 --- a/src/components/Forms.tsx +++ b/src/components/Forms.tsx @@ -1,8 +1,21 @@ -import React from 'react'; +import React, { LabelHTMLAttributes } from 'react'; import { createComponent } from '@lit/react'; -export const FormLabel = createComponent({ +const WFormLabel = createComponent({ tagName: 'label', react: React, elementClass: HTMLLabelElement, -}); \ No newline at end of file +}); + +export const FormLabel = (props: LabelHTMLAttributes) => { + const { form, ...restProps } = props; + return ; +}; \ No newline at end of file diff --git a/src/components/Typography.tsx b/src/components/Typography.tsx new file mode 100644 index 0000000..86d8e91 --- /dev/null +++ b/src/components/Typography.tsx @@ -0,0 +1,221 @@ +import React, { useMemo } from "react"; +import '../../fonts/roboto.css'; + +type TypographyProps = { + children: React.ReactNode; + variant?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "label"; + className?: string; + color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'on-primary' | 'on-secondary' | 'on-tertiary' | 'on-error' | string; + align?: "left" | "center" | "right"; + style?: React.CSSProperties; + noWrap?: boolean; + id?: string; + size?: "small" | "medium" | "large" | "auto"; +}; + +export const Typography = ({ children, variant = "span", className, color = "", align, style, noWrap, id, size = "auto" }: TypographyProps) => { + const clr = useMemo(() => { + if (color === 'primary') return 'var(--md-sys-color-primary)'; + if (color === 'secondary') return 'var(--md-sys-color-secondary)'; + if (color === 'tertiary') return 'var(--md-sys-color-tertiary)'; + if (color === 'error') return 'var(--md-sys-color-error)'; + if (color === 'on-primary') return 'var(--md-sys-color-on-primary)'; + if (color === 'on-secondary') return 'var(--md-sys-color-on-secondary)'; + if (color === 'on-tertiary') return 'var(--md-sys-color-on-tertiary)'; + if (color === 'on-error') return 'var(--md-sys-color-on-error)'; + return color; + }, [color]); + + const sz = useMemo(() => { + if (size === 'auto') { + const sizes = { + h1: 'large', + h2: 'large', + h3: 'medium', + h4: 'medium', + h5: 'small', + h6: 'small', + p: 'large', + span: 'large', + label: 'large', + }; + return sizes[variant as keyof typeof sizes]; + }; + if (size === 'small') return 'small'; + if (size === 'medium') return 'medium'; + if (size === 'large') return 'large'; + }, [size]); + + if (variant === "h1") { + return ( +

+ {children} +

+ ); + }; + + if (variant === "h2") { + return ( +

+ {children} +

+ ); + } + + if (variant === "h3") { + return ( +

+ {children} +

+ ); + } + + if (variant === "h4") { + return ( +

+ {children} +

+ ); + } + + if (variant === "h5") { + return ( +
+ {children} +
+ ); + } + + if (variant === "h6") { + return ( +
+ {children} +
+ ); + } + + if (variant === "p") { + return ( +

+ {children} +

+ ); + } + + if (variant === "span") { + return ( + + {children} + + ); + } + + if (variant === "label") { + return ( + + ); + } + + return null; +}; diff --git a/src/hooks/useTheme.tsx b/src/hooks/useTheme.tsx index d3cd93c..4bcad73 100644 --- a/src/hooks/useTheme.tsx +++ b/src/hooks/useTheme.tsx @@ -12,8 +12,8 @@ export function ThemeProvider({ children, theme, scheme }: { children: React.Rea {` body { - --md-ref-typeface-brand: 'Open Sans'; - --md-ref-typeface-plain: system-ui; + --md-ref-typeface-brand: 'Roboto Flex'; + --md-ref-typeface-plain: 'Roboto Flex'; --md-sys-color-primary: ${hexFromArgb(theme.schemes[scheme].primary)}; --md-sys-color-primary-container: ${hexFromArgb(theme.schemes[scheme].primaryContainer)}; @@ -51,7 +51,57 @@ export function ThemeProvider({ children, theme, scheme }: { children: React.Rea --md-sys-color-on-tertiary-container: ${hexFromArgb(theme.schemes[scheme].onTertiaryContainer)}; --md-sys-color-on-error: ${hexFromArgb(theme.schemes[scheme].onError)}; --md-sys-color-on-error-container: ${hexFromArgb(theme.schemes[scheme].onErrorContainer)}; + + --md-sys-typescale-headline-small-font: 'Roboto Flex'; + --md-sys-typescale-headline-medium-font: 'Roboto Flex'; + --md-sys-typescale-headline-large-font: 'Roboto Flex'; + + --md-sys-typescale-headline-small-size: 24px; + --md-sys-typescale-headline-medium-size: 32px; + --md-sys-typescale-headline-large-size: 40px; + + --md-sys-typescale-headline-small-weight: 400; + --md-sys-typescale-headline-medium-weight: 400; + --md-sys-typescale-headline-large-weight: 400; + + --md-sys-typescale-headline-small-line-height: 32px; + --md-sys-typescale-headline-medium-line-height: 40px; + --md-sys-typescale-headline-large-line-height: 48px; + + --md-sys-typescale-body-small-font: 'Roboto Flex'; + --md-sys-typescale-body-medium-font: 'Roboto Flex'; + --md-sys-typescale-body-large-font: 'Roboto Flex'; + + --md-sys-typescale-body-small-size: 12px; + --md-sys-typescale-body-medium-size: 14px; + --md-sys-typescale-body-large-size: 16px; + + --md-sys-typescale-body-small-weight: 400; + --md-sys-typescale-body-medium-weight: 400; + --md-sys-typescale-body-large-weight: 400; + + --md-sys-typescale-body-small-line-height: 16px; + --md-sys-typescale-body-medium-line-height: 20px; + --md-sys-typescale-body-large-line-height: 24px; + + + --md-sys-typescale-label-small-font: 'Roboto Flex'; + --md-sys-typescale-label-medium-font: 'Roboto Flex'; + --md-sys-typescale-label-large-font: 'Roboto Flex'; + + --md-sys-typescale-label-small-size: 12px; + --md-sys-typescale-label-medium-size: 14px; + --md-sys-typescale-label-large-size: 16px; + + --md-sys-typescale-label-small-weight: 400; + --md-sys-typescale-label-medium-weight: 400; + --md-sys-typescale-label-large-weight: 400; + + --md-sys-typescale-label-small-line-height: 16px; + --md-sys-typescale-label-medium-line-height: 20px; + --md-sys-typescale-label-large-line-height: 24px; + background-color: var(--md-sys-color-background); } `} diff --git a/src/index.tsx b/src/index.tsx index 68cfa32..2248567 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,6 +6,8 @@ import { Button } from './components/Button'; import { Box } from "./components/Box"; import { Checkbox } from "./components/Checkbox"; import { Switch } from "./components/Switch"; +import { Typography } from "./components/Typography"; +import { FormLabel } from "./components/Forms"; const mountApp = async () => { const rootContainer = document.getElementById('root'); @@ -19,14 +21,23 @@ const mountApp = async () => { const root = createRoot(rootContainer); root.render( - + + Hello + Hello + + + Hello + );