Skip to content

Commit f78a861

Browse files
committed
Convert entire library to Typescript
1 parent 04ddccc commit f78a861

File tree

143 files changed

+4843
-5248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4843
-5248
lines changed

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
"version": "2.2.0",
44
"license": "SEE LICENSE IN LICENSE",
55
"repository": "https://github.com/zigurous/react-components",
6-
"source": "src/index.js",
6+
"source": "src/index.ts",
77
"main": "dist/index.js",
88
"module": "dist/index.modern.js",
99
"unpkg": "dist/index.umd.js",
1010
"dependencies": {
11-
"classnames": "^2.3.1",
12-
"prismjs": "^1.28.0",
13-
"prop-types": "^15.8.1",
14-
"react-cookie": "^4.1.1",
11+
"classnames": "^2.5.1",
12+
"prismjs": "^1.29.0",
13+
"react-cookie": "^7.2.1",
1514
"react-image-lightbox": "^5.1.4"
1615
},
1716
"devDependencies": {
17+
"@types/prismjs": "^1.26.4",
18+
"@types/react": "^18.1.0",
19+
"@types/react-dom": "^18.1.0",
1820
"clipboardy": "^3.0.0",
1921
"cross-env": "^7.0.3",
20-
"microbundle-crl": "^0.13.11",
22+
"microbundle": "^0.15.1",
2123
"react": "^18.1.0",
2224
"react-dom": "^18.1.0",
2325
"svg2js": "^0.0.4-alpha1"
@@ -27,8 +29,8 @@
2729
"react-dom": "^18.1.0"
2830
},
2931
"scripts": {
30-
"build": "microbundle-crl --compress --css-modules \"[local]\" --globals react=React,react-dom=ReactDOM",
31-
"start": "microbundle-crl watch --no-compress --globals react=React,react-dom=ReactDOM",
32+
"build": "microbundle --compress --jsx React.createElement --jsxFragment React.Fragment --globals react=React,react-dom=ReactDOM",
33+
"start": "microbundle watch --no-compress --jsx React.createElement --jsxFragment React.Fragment --globals react=React,react-dom=ReactDOM",
3234
"predeploy": "yarn build",
3335
"prepare": "yarn build"
3436
},
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
11
import classNames from 'classnames';
2-
import PropTypes from 'prop-types';
32
import React from 'react';
43
import Link from './Link';
5-
import Logo from './Logo';
4+
import Logo, { LogoProps } from './Logo';
5+
import type { LinkType, Theme } from '../types';
66

7-
function AppFooter({
7+
export interface AppFooterProps {
8+
bordered?: boolean;
9+
className?: string;
10+
copyright?: React.ReactNode;
11+
hideLogo?: boolean;
12+
LinkElementType?: React.ElementType;
13+
links?: LinkType[];
14+
logoProps?: LogoProps;
15+
onLinkClick?: (link: LinkType) => void;
16+
sticky?: boolean;
17+
theme?: Theme | string;
18+
transparent?: boolean;
19+
}
20+
21+
export default function AppFooter({
822
bordered = false,
923
className,
1024
copyright,
1125
hideLogo = false,
1226
LinkElementType = 'a',
13-
links = [],
27+
links,
28+
logoProps,
1429
onLinkClick,
15-
onLogoClick,
1630
sticky = false,
1731
theme,
1832
transparent = false,
19-
}) {
33+
}: AppFooterProps) {
2034
return (
2135
<footer
2236
className={classNames(
2337
'app-footer',
2438
{ 'app-footer--bordered': bordered },
2539
{ 'app-footer--transparent': transparent },
2640
{ 'app-footer--sticky': sticky },
27-
className
41+
className,
2842
)}
2943
data-theme={theme}
3044
>
3145
<div className="container">
3246
<div className="row align-items-center margin-top-lg margin-bottom-lg">
3347
<div className="col font-xs font-weight-500">
3448
<span>
35-
{!hideLogo && <Logo onClick={onLogoClick} size="xs" />}
49+
{!hideLogo && <Logo size="xs" {...logoProps} />}
3650
{copyright && (
3751
<span className="copyright margin-left-xl margin-right-xl">
3852
{copyright}
@@ -41,11 +55,11 @@ function AppFooter({
4155
</span>
4256
{links && links.length > 0 && (
4357
<span className="links">
44-
{links.map((link) => (
58+
{links.map(link => (
4559
<Link
4660
aria-label={link.name}
61+
as={LinkElementType}
4762
className="color-inherit margin-left-md margin-right-md"
48-
ElementType={link.ElementType || LinkElementType}
4963
external={link.external}
5064
key={link.id || link.to}
5165
onClick={() => {
@@ -66,19 +80,3 @@ function AppFooter({
6680
</footer>
6781
);
6882
}
69-
70-
AppFooter.propTypes = {
71-
bordered: PropTypes.bool,
72-
className: PropTypes.string,
73-
copyright: PropTypes.node,
74-
hideLogo: PropTypes.bool,
75-
LinkElementType: PropTypes.elementType,
76-
links: PropTypes.arrayOf(PropTypes.shape(Link.propTypes)),
77-
onLinkClick: PropTypes.func,
78-
onLogoClick: PropTypes.func,
79-
sticky: PropTypes.bool,
80-
theme: PropTypes.string,
81-
transparent: PropTypes.bool,
82-
};
83-
84-
export default AppFooter;

src/components/AppHeader.js

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/components/AppHeader.tsx

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import classNames from 'classnames';
2+
import React from 'react';
3+
import Logo, { LogoProps } from './Logo';
4+
import NavBar from './NavBar';
5+
import NavMenu from './NavMenu';
6+
import SocialNavLinks, { SocialNavLinksProps } from './SocialNavLinks';
7+
import type { LinkType, SocialLinkType, Theme } from '../types';
8+
9+
export interface AppHeaderProps {
10+
bordered?: boolean;
11+
className?: string;
12+
fluid?: boolean;
13+
hideLogo?: boolean;
14+
hideNavigation?: boolean;
15+
hideSocialLinks?: boolean;
16+
LinkElementType?: React.ElementType;
17+
links?: LinkType[];
18+
location?: Location | null;
19+
logoProps?: LogoProps;
20+
onLinkClick?: (link: LinkType) => void;
21+
rootElement?: string;
22+
socialLinks?: SocialLinkType[];
23+
socialNavLinksProps?: SocialNavLinksProps;
24+
sticky?: boolean;
25+
theme?: Theme | string;
26+
transparent?: boolean;
27+
}
28+
29+
export default function AppHeader({
30+
bordered = false,
31+
className,
32+
fluid = false,
33+
hideLogo = false,
34+
hideNavigation = false,
35+
hideSocialLinks = false,
36+
LinkElementType = 'a',
37+
links,
38+
location = typeof window !== 'undefined' ? window.location : null,
39+
logoProps,
40+
onLinkClick,
41+
rootElement = 'body',
42+
socialLinks,
43+
socialNavLinksProps = { iconInnerPadding: 10, iconSize: 20 },
44+
sticky = false,
45+
theme,
46+
transparent = false,
47+
}: AppHeaderProps) {
48+
return (
49+
<header
50+
className={classNames(
51+
'app-header',
52+
{ 'app-header--bordered': bordered },
53+
{ 'app-header--transparent': transparent },
54+
{ 'app-header--sticky': sticky },
55+
className,
56+
)}
57+
data-theme={theme}
58+
>
59+
<div
60+
className={classNames({
61+
container: !fluid,
62+
'container-fluid': fluid,
63+
})}
64+
>
65+
<div className="app-header__content left">
66+
{!hideLogo && <Logo size="sm" {...logoProps} />}
67+
{!hideNavigation && (
68+
<NavBar
69+
LinkElementType={LinkElementType}
70+
links={links}
71+
location={location}
72+
onLinkClick={onLinkClick}
73+
/>
74+
)}
75+
</div>
76+
<div className="app-header__content right">
77+
{!hideSocialLinks && socialLinks && socialLinks.length > 0 && (
78+
<SocialNavLinks links={socialLinks} {...socialNavLinksProps} />
79+
)}
80+
{!hideNavigation && (
81+
<NavMenu
82+
hideSocialLinks={hideSocialLinks}
83+
LinkElementType={LinkElementType}
84+
links={links}
85+
location={location}
86+
onLinkClick={onLinkClick}
87+
rootElement={rootElement}
88+
socialLinks={socialLinks}
89+
theme={theme}
90+
/>
91+
)}
92+
</div>
93+
</div>
94+
</header>
95+
);
96+
}

0 commit comments

Comments
 (0)