Skip to content

Commit

Permalink
Fix many warnings, upgrade versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Aug 15, 2021
1 parent 90c2bea commit 6d2e0a2
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 147 deletions.
1 change: 1 addition & 0 deletions dist/avatar/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export declare enum AvatarStyle {
}
export interface Props {
avatarStyle: AvatarStyle;
className?: string;
style?: React.CSSProperties;
}
export default class Avatar extends React.Component<Props> {
Expand Down
2 changes: 1 addition & 1 deletion dist/avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var Avatar = /** @class */ (function (_super) {
var _a = this, path1 = _a.path1, path2 = _a.path2, path3 = _a.path3, mask1 = _a.mask1, mask2 = _a.mask2, mask3 = _a.mask3;
var avatarStyle = this.props.avatarStyle;
var circle = avatarStyle === AvatarStyle.Circle;
return (React.createElement("svg", { style: this.props.style, width: "264px", height: "280px", viewBox: "0 0 264 280", version: "1.1", xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink" },
return (React.createElement("svg", { style: this.props.style, className: this.props.className, width: "264px", height: "280px", viewBox: "0 0 264 280", version: "1.1", xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink" },
React.createElement("desc", null, "Created with getavataaars.com"),
React.createElement("defs", null,
React.createElement("circle", { id: path1, cx: "120", cy: "120", r: "120" }),
Expand Down
6 changes: 4 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';
import { OptionContext } from './options';
export { default as Avatar, AvatarStyle } from './avatar';
export { Option, OptionContext, allOptions } from './options';
export interface Props {
avatarStyle: string;
className?: string;
style?: React.CSSProperties;
topType?: string;
accessoriesType?: string;
Expand All @@ -23,7 +25,7 @@ export interface Props {
}
export default class AvatarComponent extends React.Component<Props> {
static childContextTypes: {
optionContext: any;
optionContext: PropTypes.Requireable<OptionContext>;
};
private optionContext;
getChildContext(): {
Expand All @@ -36,7 +38,7 @@ export default class AvatarComponent extends React.Component<Props> {
}
export declare class Piece extends React.Component<Props> {
static childContextTypes: {
optionContext: any;
optionContext: PropTypes.Requireable<OptionContext>;
};
private optionContext;
getChildContext(): {
Expand Down
12 changes: 6 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ var AvatarComponent = /** @class */ (function (_super) {
AvatarComponent.prototype.getChildContext = function () {
return { optionContext: this.optionContext };
};
AvatarComponent.prototype.UNSAFE_componentWillMount = function () {
AvatarComponent.prototype.componentWillMount = function () {
this.updateOptionContext(this.props);
};
AvatarComponent.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
AvatarComponent.prototype.componentWillReceiveProps = function (nextProps) {
this.updateOptionContext(nextProps);
};
AvatarComponent.prototype.render = function () {
var _a = this.props, avatarStyle = _a.avatarStyle, style = _a.style;
return React.createElement(avatar_1.default, { avatarStyle: avatarStyle, style: style });
var _a = this.props, avatarStyle = _a.avatarStyle, style = _a.style, className = _a.className;
return React.createElement(avatar_1.default, { avatarStyle: avatarStyle, style: style, className: className });
};
AvatarComponent.prototype.updateOptionContext = function (props) {
var data = {};
Expand Down Expand Up @@ -76,10 +76,10 @@ var Piece = /** @class */ (function (_super) {
Piece.prototype.getChildContext = function () {
return { optionContext: this.optionContext };
};
Piece.prototype.UNSAFE_componentWillMount = function () {
Piece.prototype.componentWillMount = function () {
this.updateOptionContext(this.props);
};
Piece.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
Piece.prototype.componentWillReceiveProps = function (nextProps) {
this.updateOptionContext(nextProps);
};
Piece.prototype.render = function () {
Expand Down
3 changes: 1 addition & 2 deletions dist/options/OptionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ var OptionContext = /** @class */ (function () {
OptionContext.prototype.setOptions = function (key, options) {
var _a;
this.setState((_a = {},
_a[key] = __assign(__assign({}, this.state[key]), { key: key,
options: options }),
_a[key] = __assign(__assign({}, this.state[key]), { key: key, options: options }),
_a));
};
OptionContext.prototype.setState = function (state) {
Expand Down
8 changes: 5 additions & 3 deletions dist/options/Selector.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';
import Option from './Option';
import OptionContext from './OptionContext';
export interface Props {
option: Option;
defaultOption: React.ComponentClass | string;
}
export default class Selector extends React.Component<Props> {
static contextTypes: {
optionContext: any;
optionContext: PropTypes.Requireable<OptionContext>;
};
private get optionContext();
componentWillMount(): void;
componentWillUpdate(nextProps: Props & {
UNSAFE_componentWillMount(): void;
UNSAFE_componentWillUpdate(nextProps: Props & {
children?: React.ReactNode;
}): void;
componentWillUnmount(): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/options/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var Selector = /** @class */ (function (_super) {
var values = React.Children.map(children,
// TODO: also validate and throw error if we don't see optionValue
function (child) { return getComponentOptionValue(child.type); });
if (new Set(values).size !== values.length) {
if (new Set(values).size !== (values === null || values === void 0 ? void 0 : values.length)) {
throw new Error('Duplicate values');
}
this.optionContext.setOptions(option.key, values);
Expand Down
29 changes: 21 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "React component for avataaars ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc"
},
"keywords": [
"react",
"avatar"
Expand All @@ -12,18 +15,18 @@
"author": "Fang-Pen Lin <[email protected]>",
"license": "MIT",
"peerDependencies": {
"react": "^16.0.0"
"react": "^17.0.0"
},
"devDependencies": {
"@types/react": "^16.0.25",
"@types/react": "^17.0.0",
"import-sort-style-renke": "^4.2.0",
"tslint": "^5.8.0",
"tslint-config-standard": "^7.0.0",
"tslint-react": "^3.2.0",
"typescript": "^2.6.2"
"tslint": "^6.1.3",
"tslint-config-standard": "^9.0.0",
"tslint-react": "^5.0.0",
"typescript": "^4.3.5"
},
"dependencies": {
"lodash": ">=4.17.11",
"lodash": ">=4.17.21",
"prop-types": "^15.6.0"
},
"importSort": {
Expand All @@ -35,5 +38,15 @@
"parser": "typescript",
"style": "import-sort-style-renke"
}
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"jsxSingleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": true
}
}
}
6 changes: 3 additions & 3 deletions src/options/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Selector extends React.Component<Props> {
return this.context.optionContext
}

componentWillMount () {
UNSAFE_componentWillMount () {
const { option, defaultOption } = this.props
const { optionContext } = this
const defaultValue = (
Expand All @@ -42,7 +42,7 @@ export default class Selector extends React.Component<Props> {
}
}

componentWillUpdate (nextProps: Props & { children?: React.ReactNode }) {
UNSAFE_componentWillUpdate (nextProps: Props & { children?: React.ReactNode }) {
this.updateOptionValues(nextProps)
}

Expand Down Expand Up @@ -79,7 +79,7 @@ export default class Selector extends React.Component<Props> {
// TODO: also validate and throw error if we don't see optionValue
child => getComponentOptionValue((child as any).type)
)
if (new Set(values).size !== values.length) {
if (new Set(values).size !== values?.length) {
throw new Error('Duplicate values')
}
this.optionContext.setOptions(option.key, values)
Expand Down
13 changes: 10 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"declaration": true,
"newLine": "lf",
"outDir": "./dist",
"lib": ["es6", "dom"]
"lib": [
"es6",
"dom"
]
},
"types": ["jest", "node"]
}
"types": [
"jest",
"node"
]
}
Loading

0 comments on commit 6d2e0a2

Please sign in to comment.