mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* base-64 typings
* formatting and indenting
* feat: add typings for watchpack
* fix: improve missing typings
* Port from https://github.com/agileek/typings-vis/blob/master/vs.d.ts
* Fix travis build failures
* Port PR https://github.com/agileek/typings-vis/pull/12
* Fix travis build failures
* added tsconfig and tslint
* removed patch number
* added tests
* made it export like base64-js
* removed old code
* formatted code
* fix: add files field in tsconfig.json for expected publishment
* fix: improve most missing typings
* feat: upgrade to v3.0.0
* feat: upgrade to tapbale v0.2.5
* Types 2.0 (#13261)
* updating typing of the latest 7.0 react-autosuggest
* updating typing of react-autosuggest 7.0
* update typings for react-autosuggest 7.0
* Remove '+' from header versions, so they can be parsed (#13239)
* Updated masonry-layout to fix linting errors (#13272)
* Updated masonry-layout to fix linting errors
* Fixed the tests I could fix.
* Removed patch version
* Add redux-persist and basic transformers (#13389)
* Add definitions for redux-persist
* Add missin generic types
* Add definitions for filter transformer
* Add definitions for encrypt transformer
* Fix header
* Add definitions for compress transformer
* Delete unnecessary linter configs
* Change way of importing, fix tests
* fix: angulartics type definition for ES6 import
* fix: lint error
* fix scalar type config (#13398)
The `GraphQLScalarTypeConfig` interface had incorrect types. Correct types may be seen here: 379a308439/src/type/definition.js (L348-L350)
* [interact.js] Update module names (#13316)
Update CommonJS module name as it was changed in version 1.2.7.
AMD module name is also different from both new and old CommonJS module names, so a separate declaration was created for that as well.
* Add definitions for redux-recycle (#13424)
* Add definitions for redux-recycle
* Fix linter errors
* [jest] add type definition for toHaveBeenLastCalledWith (#13038)
* remove ajv because the package bundles its own types (#13028)
* Updated type definitions to yfiles for HTML 2.0. (#13332)
* Updated type definitions to yFiles for HTML 2.0.
* Updated type definitions to yfiles for HTML 2.0.
* Added contact in yfiles .d.ts header.
* Add redux-batched-actions typings. (#13054)
* Add types for mailgen (#13080)
* Typings for cordova-sqlite-storage (#13081)
* Add flatpickr definitions (#13083)
* Add pouch-redux-middleware typing (#13071)
* Add pouch-redux-middleware typing
* Fix <> in comment
* Add declaration for crc (#13068)
* Updated jquery.dataTables for 1.10.9 (#13099)
Release Notes: https://cdn.datatables.net/1.10.9/
* Moved legacy browser settings to its own data type.
* Added 'aIds' property on legacy settings object for mapping row ids to data indexes.
* Added 'rowIdFn' function to legacy settings object to get a row's id from the row's data.
* chore(lint): change vis typing to external module (#13399)
* Fix cordova-sqlite-storage lint
* Lint `vis`: Remove "I" prefix for namespaces
* Change cordova-sqlite-storage back. Linter was wrong.
362 lines
11 KiB
TypeScript
362 lines
11 KiB
TypeScript
//region Imports
|
|
import React = require('react');
|
|
import ReactDOM = require('react-dom');
|
|
import { Autosuggest, SuggestionSelectedEventData } from 'react-autosuggest';
|
|
//endregion
|
|
|
|
interface Language {
|
|
name: string;
|
|
year: number;
|
|
}
|
|
|
|
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions#Using_Special_Characters
|
|
function escapeRegexCharacters(str: string): string {
|
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
}
|
|
|
|
export class ReactAutosuggestBasicTest extends React.Component<any, any> {
|
|
//region Fields
|
|
public static languages: Language[] = [
|
|
{name: 'C', year: 1972},
|
|
{name: 'C#', year: 2000},
|
|
{name: 'C++', year: 1983},
|
|
{name: 'Clojure', year: 2007},
|
|
{name: 'Elm', year: 2012},
|
|
{name: 'Go', year: 2009},
|
|
{name: 'Haskell', year: 1990},
|
|
{name: 'Java', year: 1995},
|
|
{name: 'Javascript', year: 1995},
|
|
{name: 'Perl', year: 1987},
|
|
{name: 'PHP', year: 1995},
|
|
{name: 'Python', year: 1991},
|
|
{name: 'Ruby', year: 1995},
|
|
{name: 'Scala', year: 2003}
|
|
];
|
|
//endregion
|
|
|
|
|
|
//region Constructor
|
|
constructor(props: any) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
value: '',
|
|
suggestions: this.getSuggestions('')
|
|
};
|
|
}
|
|
//endregion
|
|
|
|
//region Rendering methods
|
|
public render(): JSX.Element {
|
|
const {value, suggestions} = this.state;
|
|
const inputProps = {
|
|
placeholder: `Type 'c'`,
|
|
value,
|
|
onChange: this.onChange.bind(this)
|
|
};
|
|
|
|
const theme = {
|
|
input: 'themed-input-class',
|
|
container: 'themed-container-class',
|
|
suggestionFocused: 'active'
|
|
}
|
|
|
|
return <Autosuggest suggestions={suggestions}
|
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested.bind(this)}
|
|
getSuggestionValue={this.getSuggestionValue}
|
|
renderSuggestion={this.renderSuggestion}
|
|
onSuggestionSelected={this.onSuggestionsSelected}
|
|
alwaysRenderSuggestions={true}
|
|
inputProps={inputProps}
|
|
theme={theme}
|
|
/>;
|
|
}
|
|
|
|
protected onSuggestionsSelected(event: React.FormEvent<any>, data: SuggestionSelectedEventData<Language>): void {
|
|
alert(`Selected language is ${data.suggestion.name} (${data.suggestion.year}).`);
|
|
}
|
|
|
|
protected renderSuggestion(suggestion: Language): JSX.Element {
|
|
return <span>{suggestion.name}</span>;
|
|
}
|
|
//endregion
|
|
|
|
//region Event handlers
|
|
protected onChange(event: React.FormEvent<any>, {newValue, method}: any): void {
|
|
this.setState({
|
|
value: newValue
|
|
});
|
|
}
|
|
|
|
protected onSuggestionsFetchRequested({ value }: any): void {
|
|
this.setState({
|
|
suggestions: this.getSuggestions(value)
|
|
});
|
|
}
|
|
//endregion
|
|
|
|
//region Helper methods
|
|
protected getSuggestions(value: string): Language[] {
|
|
const escapedValue = escapeRegexCharacters(value.trim());
|
|
|
|
if (escapedValue === '') {
|
|
return [];
|
|
}
|
|
|
|
const regex = new RegExp('^' + escapedValue, 'i');
|
|
|
|
return ReactAutosuggestBasicTest.languages.filter(language => regex.test(language.name));
|
|
}
|
|
|
|
protected getSuggestionValue(suggestion: Language): string {
|
|
return suggestion.name;
|
|
}
|
|
//endregion
|
|
}
|
|
|
|
ReactDOM.render(<ReactAutosuggestBasicTest />, document.getElementById('app'));
|
|
|
|
interface LanguageGroup {
|
|
title: string;
|
|
languages: Language[];
|
|
}
|
|
|
|
export class ReactAutosuggestMultipleTest extends React.Component<any, any> {
|
|
//region Fields
|
|
public static languages: LanguageGroup[] = [
|
|
{
|
|
title: '1970s',
|
|
languages: [
|
|
{name: 'C', year: 1972}
|
|
]
|
|
},
|
|
{
|
|
title: '1980s',
|
|
languages: [
|
|
{name: 'C++', year: 1983},
|
|
{name: 'Perl', year: 1987}
|
|
]
|
|
},
|
|
{
|
|
title: '1990s',
|
|
languages: [
|
|
{name: 'Haskell', year: 1990},
|
|
{name: 'Python', year: 1991},
|
|
{name: 'Java', year: 1995},
|
|
{name: 'Javascript', year: 1995},
|
|
{name: 'PHP', year: 1995},
|
|
{name: 'Ruby', year: 1995}
|
|
]
|
|
},
|
|
{
|
|
title: '2000s',
|
|
languages: [
|
|
{name: 'C#', year: 2000},
|
|
{name: 'Scala', year: 2003},
|
|
{name: 'Clojure', year: 2007},
|
|
{name: 'Go', year: 2009}
|
|
]
|
|
},
|
|
{
|
|
title: '2010s',
|
|
languages: [
|
|
{name: 'Elm', year: 2012}
|
|
]
|
|
}
|
|
];
|
|
//endregion
|
|
|
|
//region Constructor
|
|
constructor(props: any) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
value: '',
|
|
suggestions: this.getSuggestions('')
|
|
};
|
|
}
|
|
//endregion
|
|
|
|
//region Rendering methods
|
|
public render(): JSX.Element {
|
|
const { value, suggestions } = this.state;
|
|
const inputProps = {
|
|
placeholder: `Type 'c'`,
|
|
value,
|
|
onChange: this.onChange.bind(this)
|
|
};
|
|
|
|
return <Autosuggest multiSection={true}
|
|
suggestions={suggestions}
|
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested.bind(this)}
|
|
onSuggestionSelected={this.onSuggestionSelected}
|
|
getSuggestionValue={this.getSuggestionValue}
|
|
renderSuggestion={this.renderSuggestion}
|
|
renderSectionTitle={this.renderSectionTitle}
|
|
getSectionSuggestions={this.getSectionSuggestions}
|
|
inputProps={inputProps} />;
|
|
}
|
|
|
|
protected onSuggestionSelected(event: React.FormEvent<any>, data: SuggestionSelectedEventData<Language>): void {
|
|
const language = data.suggestion as Language;
|
|
|
|
alert(`Selected language is ${language.name} (${language.year}).`);
|
|
}
|
|
|
|
protected renderSuggestion(suggestion: Language): JSX.Element {
|
|
return <span>{suggestion.name}</span>;
|
|
}
|
|
|
|
protected renderSectionTitle(section: LanguageGroup): JSX.Element {
|
|
return <strong>{section.title}</strong>;
|
|
}
|
|
//endregion
|
|
|
|
//region Event handlers
|
|
protected onChange(event: React.FormEvent<any>, { newValue, method }: any): void {
|
|
this.setState({
|
|
value: newValue
|
|
});
|
|
}
|
|
|
|
protected onSuggestionsFetchRequested({ value }: any): void {
|
|
this.setState({
|
|
suggestions: this.getSuggestions(value)
|
|
});
|
|
}
|
|
//endregion
|
|
|
|
//region Helper methods
|
|
protected getSuggestions(value: string): LanguageGroup[] {
|
|
const escapedValue = escapeRegexCharacters(value.trim());
|
|
|
|
if (escapedValue === '') {
|
|
return [];
|
|
}
|
|
|
|
const regex = new RegExp('^' + escapedValue, 'i');
|
|
|
|
return ReactAutosuggestMultipleTest.languages
|
|
.map(section => {
|
|
return {
|
|
title: section.title,
|
|
languages: section.languages.filter(language => regex.test(language.name))
|
|
};
|
|
})
|
|
.filter(section => section.languages.length > 0);
|
|
}
|
|
|
|
protected getSuggestionValue(suggestion: Language) {
|
|
return suggestion.name;
|
|
}
|
|
|
|
protected getSectionSuggestions(section: LanguageGroup) {
|
|
return section.languages;
|
|
}
|
|
//endregion
|
|
}
|
|
|
|
ReactDOM.render(<ReactAutosuggestMultipleTest />, document.getElementById('app'));
|
|
|
|
interface IPerson {
|
|
first: string;
|
|
last: string;
|
|
twitter: string;
|
|
}
|
|
|
|
export class ReactAutosuggestCustomTest extends React.Component<any, any> {
|
|
//region Fields
|
|
public static people: IPerson[] = [
|
|
{first: 'Charlie', last: 'Brown', twitter: 'dancounsell'},
|
|
{first: 'Charlotte', last: 'White', twitter: 'mtnmissy'},
|
|
{first: 'Chloe', last: 'Jones', twitter: 'ladylexy'},
|
|
{first: 'Cooper', last: 'King', twitter: 'steveodom'}
|
|
];
|
|
//endregion
|
|
|
|
//region Constructor
|
|
constructor(props: any) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
value: '',
|
|
suggestions: this.getSuggestions('')
|
|
};
|
|
}
|
|
//endregion
|
|
|
|
//region Rendering methods
|
|
public render(): JSX.Element {
|
|
const { value, suggestions } = this.state;
|
|
const inputProps = {
|
|
placeholder: "Type 'c'",
|
|
value,
|
|
onChange: this.onChange.bind(this)
|
|
};
|
|
|
|
return <Autosuggest suggestions={suggestions}
|
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
|
getSuggestionValue={this.getSuggestionValue}
|
|
renderSuggestion={this.renderSuggestion}
|
|
inputProps={inputProps} />;
|
|
}
|
|
|
|
protected renderSuggestion(suggestion: IPerson, { value, valueBeforeUpDown }: any): JSX.Element {
|
|
const suggestionText = `${suggestion.first} ${suggestion.last}`;
|
|
const query = (valueBeforeUpDown || value).trim();
|
|
const parts = suggestionText.split(' ').map((part: string) => {
|
|
return {
|
|
highlight: (Math.ceil(Math.random() * 10)) % 2,
|
|
text: part
|
|
}
|
|
});
|
|
|
|
return <span className={'suggestion-content ' + suggestion.twitter}>
|
|
<span className="name">
|
|
{
|
|
parts.map((part, index) => {
|
|
const className = part.highlight ? 'highlight' : undefined;
|
|
|
|
return <span className={className} key={index}>{part.text}</span>;
|
|
})
|
|
}
|
|
</span>
|
|
</span>;
|
|
}
|
|
//endregion
|
|
|
|
//region Event handlers
|
|
protected onChange(event: React.FormEvent<any>, {newValue, method}: any): void {
|
|
this.setState({
|
|
value: newValue
|
|
});
|
|
}
|
|
|
|
protected onSuggestionsFetchRequested({ value }: any): void {
|
|
this.setState({
|
|
suggestions: this.getSuggestions(value)
|
|
});
|
|
}
|
|
//endregion
|
|
|
|
//region Helper methods
|
|
protected getSuggestions(value: string): IPerson[] {
|
|
const escapedValue = escapeRegexCharacters(value.trim());
|
|
|
|
if (escapedValue === '') {
|
|
return [];
|
|
}
|
|
|
|
const regex = new RegExp('\\b' + escapedValue, 'i');
|
|
|
|
return ReactAutosuggestCustomTest.people.filter(person => regex.test(this.getSuggestionValue(person)));
|
|
}
|
|
|
|
protected getSuggestionValue(suggestion: IPerson): string {
|
|
return `${suggestion.first} ${suggestion.last}`;
|
|
}
|
|
//endregion
|
|
}
|
|
|
|
ReactDOM.render(<ReactAutosuggestCustomTest />, document.getElementById('app'));
|