Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[types][sources] add missing types #203

Merged
merged 3 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

import React from 'react';
import ReactDOM from 'react-dom';
import Avatar, {getRandomColor, ConfigProvider} from './../src';
import Avatar, {
getRandomColor,
ConfigProvider,
createAvatarComponent,
GravatarSource,
ValueSource
} from './../src';

const CustomAvatar = createAvatarComponent({
sources: [ GravatarSource, ValueSource ]
});

import './index.html';
import './demo.css';
Expand Down Expand Up @@ -67,8 +77,10 @@ class Demo extends React.Component {

_onAttachRef(ref) {
// Dummy function to test errors on reference
// eslint-disable-next-line no-console
console && console.log('Ref received', ref);
if(console) {
// eslint-disable-next-line no-console
console.log('Ref received', ref);
}
}

render() {
Expand Down Expand Up @@ -399,6 +411,13 @@ class Demo extends React.Component {
</section>
</ConfigProvider>

<section>
<h2>Avatar with only support for gravatar and value</h2>
<CustomAvatar value="JE" />
<CustomAvatar value="JE" md5Email="8c5d4c4b9ef6c68c4ff91c319d4c56be" />
<CustomAvatar githubHandle="JorgenEvens" color="#E88554" />
</section>

</div>
);
}
Expand Down
33 changes: 30 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from "react";


export interface ReactAvatarProps {
/**
* Name of the CSS class you want to add to this component alongside the default sb-avatar.
Expand Down Expand Up @@ -91,6 +90,10 @@ export interface ReactAvatarProps {
onClick?: (e: React.SyntheticEvent<any>) => any;
}

interface CreateAvatarOptions {
sources?: SourceConstructor[]
}

export interface ConfigProvider {
/**
* A list of color values as strings from which the getRandomColor picks one at random.
Expand Down Expand Up @@ -145,16 +148,40 @@ export interface CacheOptions {
sourceSize?: number
}

export interface CacheConstructor {
new (options: CacheOptions): Cache;
type CacheConstructor = new (options: CacheOptions) => Cache;

interface Source {
isCompatible: () => boolean;
get: (setState: (update: object) => void) => void;
}

type SourceConstructor = new (props: object) => Source;

const AvatarRedirectSource = SourceConstructor;
export const RedirectSource = (network: string, property: string) => AvatarRedirectSource

/**
* Universal avatar makes it possible to fetch/generate an avatar based on the information you have about that user.
* We use a fallback system that if for example an invalid Facebook ID is used it will try Google, and so on.
*/
declare const ReactAvatar: React.ComponentType<ReactAvatarProps>;

export const createAvatarComponent: (options: CreateAvatarOptions) => ReactAvatar;

export const ConfigProvider: React.ComponentType<ConfigProvider>;
export const Cache: CacheConstructor;

export const GravatarSource: SourceConstructor;
export const FacebookSource: SourceConstructor;
export const GithubSource: SourceConstructor;
export const SkypeSource: SourceConstructor;
export const ValueSource: SourceConstructor;
export const SrcSource: SourceConstructor;
export const IconSource: SourceConstructor;

export const VKontakteSource: SourceConstructor;
export const InstagramSource: SourceConstructor;
export const TwitterSource: SourceConstructor;
export const GoogleSource: SourceConstructor;

export default ReactAvatar;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"demo": "npm -s run build:demo",
"dev": "webpack-dev-server",
"serve": "npm -s run dev",
"test": "npm -s run test:lint",
"test": "npm -s run test:lint && npm -s run test:tslint",
"test:lint": "eslint src",
"test:tslint": "tslint ./index.d.ts",
"postpublish": "npm -s run publish:docs",
"publish:docs": "npm -s run build:demo && gh-pages -d build"
},
Expand Down Expand Up @@ -58,6 +59,8 @@
"gh-pages": "^2.1.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"tslint": "^6.1.2",
"typescript": "^3.8.3",
"webpack": "^4.41.4",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.10",
Expand Down
9 changes: 9 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}