code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
static resolveUrl(url, baseUrl) {
url = trim(url);
if (!url) return null;
if (startsWith(url, '#')) return null;
const { protocol } = parse(url);
if (includes(['http:', 'https:'], protocol)) {
return url.split('#')[0];
} else if (!protocol) { // eslint-disable-line no-else-return
ret... | @param {!string} url
@param {!string} baseUrl
@return {!string} | resolveUrl | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
static escapeQuotes(value, separator = ',') {
if (value === null || value === undefined) return '';
const regExp = new RegExp(`["${separator}\\r\\n]`);
if (regExp.test(value)) return `"${value.replace(/"/g, '""')}"`;
return value;
} | @param {!string} value
@param {!string=} separator
@return {!string} | escapeQuotes | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
static getRobotsUrl(url) {
const { protocol, host } = parse(url);
return format({ protocol, host, pathname: '/robots.txt' });
} | @param {!string} url
@return {!string}
@private | getRobotsUrl | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
static lowerBound(array, value, comp) {
let first = 0;
let count = array.length;
while (count > 0) {
const step = (count / 2) | 0;
let it = first + step;
if (comp(array[it], value) <= 0) {
it += 1;
first = it;
count -= step + 1;
} else {
count = step;
... | @param {!string} url
@return {!string}
@private | lowerBound | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
static checkDomainMatch(domains, hostname) {
return some(domains, domain => {
if (isRegExp(domain)) return domain.test(hostname);
return domain === hostname;
});
} | @param {!Array<!string|RegExp>} domains
@param {!string} hostname
@return {!boolean} | checkDomainMatch | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
static getSitemapUrls(sitemapXml) {
const urls = [];
sitemapXml.replace(/<loc>([^<]+)<\/loc>/g, (_, url) => {
const unescapedUrl = Helper.unescape(url);
urls.push(unescapedUrl);
return null;
});
return urls;
} | @param {!string} sitemapXml
@return {!Array<!string>} | getSitemapUrls | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
static run(port) {
const server = new Server(port);
return new Promise(resolve => void server._server.once('listening', () => {
resolve(server);
}));
} | @param {!number} port
@return {!Promise<!Server>} | run | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
setAuth(path, username, password) {
this._auths.set(path, { username, password });
} | @param {!string} path
@param {!string} username
@param {!string} password | setAuth | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
setCSP(path, csp) {
this._csps.set(path, csp);
} | @param {string} path
@param {string} csp | setCSP | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
setContent(path, content) {
this._contents.set(path, content);
} | @param {!string} path
@param {!string} content | setContent | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
setResponseDelay(path, delay) {
this._delays.set(path, delay);
} | @param {!string} path
@param {!number} delay | setResponseDelay | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
setRedirect(from, to) {
this._routes.set(from, (request, response) => {
response.writeHead(302, { location: to });
response.end();
});
} | @param {string} from
@param {string} to | setRedirect | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
_onRequest(request, response) {
this._handleError(request, response);
const { path } = parse(request.url);
response.setHeader('Content-Type', mime.getType(path));
const auth = this._auths.get(path);
if (!this._authenticate(auth, request)) {
response.writeHead(401, { 'WWW-Authenticate': 'Basic ... | @param {!IncomingMessage} request
@param {!ServerResponse} response
@private | _onRequest | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
_handleError(request, response) {
request.on('error', error => {
if (error.code === 'ECONNRESET') {
response.end();
return;
}
throw error;
});
} | @param {!IncomingMessage} request
@param {!ServerResponse} response
@private | _handleError | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
_authenticate(auth, request) {
if (!auth) return true;
const credentials = this._getCredentials(request.headers.authorization);
if (credentials === `${auth.username}:${auth.password}`) return true;
return false;
} | @param {!{username:string, password:string}} auth
@param {!IncomingMessage} request
@return {!boolean}
@private | _authenticate | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
_getCredentials(authorization = '') {
const credentials = authorization.split(' ')[1] || '';
return Buffer.from(credentials, 'base64').toString();
} | @param {!string=} authorization
@return {!string}
@private | _getCredentials | javascript | yujiosaka/headless-chrome-crawler | test/server/index.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/server/index.js | MIT |
function getParameterByName(name) {
const parsedName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
const regex = new RegExp(`[\\?&]${parsedName}=([^&#]*)`);
const results = regex.exec(location.hash);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
} | Get a URL query parameter from the hash. | getParameterByName | javascript | nikgraf/belle | docs/theme/initialize.js | https://github.com/nikgraf/belle/blob/master/docs/theme/initialize.js | MIT |
function updateStructure(targetObject, object) {
for (const componentName in object) {
if (object.hasOwnProperty(componentName)) {
for (const styleName in object[componentName]) {
if (object[componentName].hasOwnProperty(styleName)) {
targetObject[componentName][styleName] = object[compone... | Updates the deepest structure while keeping the original reference of the outer objects. | updateStructure | javascript | nikgraf/belle | docs/theme/initialize.js | https://github.com/nikgraf/belle/blob/master/docs/theme/initialize.js | MIT |
function initializeTheme() {
const theme = getParameterByName('theme');
if (theme === 'bootstrap') {
updateStructure(belle.style, bootstrap3Theme.style);
updateStructure(belle.config, bootstrap3Theme.config);
} else if (theme === 'belle-with-default-focus') {
updateStructure(belle.style, belleWithCla... | Updates the deepest structure while keeping the original reference of the outer objects. | initializeTheme | javascript | nikgraf/belle | docs/theme/initialize.js | https://github.com/nikgraf/belle/blob/master/docs/theme/initialize.js | MIT |
constructor(properties) {
super(properties);
this.childProps = sanitizeChildProps(properties);
} | ActionArea
The purpose of this component is to provide a button like behaviour for a
click like interaction within other components. Button can't be used in such
cases as it always will have it's own focus which is not desired in
components like DatePicker e.g. next month button.
Note: Use the ActionArea's onUpdate i... | constructor | javascript | nikgraf/belle | src/components/ActionArea.js | https://github.com/nikgraf/belle/blob/master/src/components/ActionArea.js | MIT |
componentWillReceiveProps(properties) {
this.childProps = sanitizeChildProps(properties);
} | Update the childProps based on the updated properties passed to the card. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/ActionArea.js | https://github.com/nikgraf/belle/blob/master/src/components/ActionArea.js | MIT |
render() {
let style = { ...actionAreaStyle.style, ...this.props.style };
if (this.state.isHovered) {
style = {
...style,
...actionAreaStyle.hoverStyle,
...this.props.hoverStyle,
};
}
if (this.state.isActive) {
style = {
...style,
...actionAreaS... | Updates the button to be release and makes sure the next onMouseEnter is
ignored. | render | javascript | nikgraf/belle | src/components/ActionArea.js | https://github.com/nikgraf/belle/blob/master/src/components/ActionArea.js | MIT |
function sanitizeChildProps(properties) {
return omit(properties, Object.keys(buttonPropTypes));
} | Returns an object with properties that are relevant for the button element.
In case a wrong or no type is defined the type of the child button will be
set to `button`. | sanitizeChildProps | javascript | nikgraf/belle | src/components/Button.js | https://github.com/nikgraf/belle/blob/master/src/components/Button.js | MIT |
function updatePseudoClassStyle(styleId, properties, preventFocusStyleForTouchAndClick) {
const baseStyle = properties.primary ? buttonStyle.primaryStyle : buttonStyle.style;
const baseDisabledStyle = properties.primary ? buttonStyle.primaryDisabledStyle : buttonStyle.disabledStyle;
const disabledStyle = {
..... | Update hover, focus & active style for the speficied styleId.
@param styleId {string} - a unique id that exists as class attribute in the DOM
@param properties {object} - the components properties optionally containing custom styles | updatePseudoClassStyle | javascript | nikgraf/belle | src/components/Button.js | https://github.com/nikgraf/belle/blob/master/src/components/Button.js | MIT |
componentWillMount() {
this.styleId = `style-id${uniqueId()}`;
updatePseudoClassStyle(this.styleId, this.props, this.preventFocusStyleForTouchAndClick);
} | Generates the style-id & inject the focus & active style. | componentWillMount | javascript | nikgraf/belle | src/components/Button.js | https://github.com/nikgraf/belle/blob/master/src/components/Button.js | MIT |
componentWillReceiveProps(properties) {
this.preventFocusStyleForTouchAndClick = has(properties, 'preventFocusStyleForTouchAndClick') ? properties.preventFocusStyleForTouchAndClick : config.preventFocusStyleForTouchAndClick;
this.setState({
childProps: sanitizeChildProps(properties),
});
removeSt... | Update the childProps based on the updated properties of the button. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/Button.js | https://github.com/nikgraf/belle/blob/master/src/components/Button.js | MIT |
componentDidUpdate() {
this.focused = false;
this.mouseDownOnButton = false;
} | Deactivate the focused attribute in order to make sure the focus animation
only runs once when the component is focused on & not after re-rendering
e.g when the user clicks the button. | componentDidUpdate | javascript | nikgraf/belle | src/components/Button.js | https://github.com/nikgraf/belle/blob/master/src/components/Button.js | MIT |
constructor(properties) {
super(properties);
const { style, ...childProps } = properties; // eslint-disable-line no-unused-vars
this.childProps = childProps;
} | Card component with a light shadow.
This component will apply any attribute to the div that has been provided as
property & is valid for a div. | constructor | javascript | nikgraf/belle | src/components/Card.js | https://github.com/nikgraf/belle/blob/master/src/components/Card.js | MIT |
componentWillReceiveProps(properties) {
const { style, ...childProps } = properties; // eslint-disable-line no-unused-vars
this.childProps = childProps;
} | Update the childProps based on the updated properties passed to the card. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/Card.js | https://github.com/nikgraf/belle/blob/master/src/components/Card.js | MIT |
render() {
const divStyle = { ...cardStyle.style, ...this.props.style };
return (
<div {...this.childProps} style={ divStyle }>
{ this.props.children }
</div>
);
} | Update the childProps based on the updated properties passed to the card. | render | javascript | nikgraf/belle | src/components/Card.js | https://github.com/nikgraf/belle/blob/master/src/components/Card.js | MIT |
function updatePseudoClassStyle(styleId, caretStyleId, properties) {
const hoverStyle = {
...style.hoverStyle,
...properties.hoverStyle,
};
const focusStyle = {
...style.focusStyle,
...properties.focusStyle,
};
const disabledHoverStyle = {
...style.disabledHoverStyle,
...properties.dis... | Update hover style for the specified styleId.
@param styleId {string} - a unique id that exists as class attribute in the DOM
@param caretStyleId {string} - unique is assigned as class to caret span
@param properties {object} - the components properties optionally containing hoverStyle | updatePseudoClassStyle | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
function sanitizeWrapperProps(properties) {
return omit(properties, [
'style',
'aria-label',
'aria-disabled',
]);
} | Returns an object with properties that are relevant for the wrapper div. | sanitizeWrapperProps | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
function sanitizeInputProps(properties) {
return omit(properties, Object.keys(comboBoxPropTypes));
} | Returns an object with properties that are relevant for the input box. | sanitizeInputProps | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
function sanitizeCaretProps(properties) {
return omit(properties, [
'style',
'className',
'onClick',
'tabIndex',
]);
} | Returns an object with properties that are relevant for the wrapping div of
the selected option. | sanitizeCaretProps | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
function sanitizeMenuProps(properties) {
return omit(properties, [
'style',
'ref',
'role',
]);
} | Returns an object with properties that are relevant for the combo-box menu. | sanitizeMenuProps | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
function filterFunc(inputValue, optionValue) {
if (inputValue && optionValue) {
return optionValue.toLowerCase().indexOf(inputValue.toLowerCase()) > -1;
}
return false;
} | Default function used for filtering options. | filterFunc | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_getHint() {
if (this.state.isOpen) {
const filteredOptions = this.filteredOptions;
if (filteredOptions && filteredOptions.length > 0) {
let hint;
const focusedOptionIndex = this.state.focusedOptionIndex;
const inputValue = this.state.inputValue;
if (focusedOptionIndex >=... | This method will calculate the hint that should be present in comboBox at some point in time. Rules:
1. If menu is not open hint is undefined
2. If menu is open but there are no filteredOptions hint is undefined
3. If if some option is highlighted hint is equal to its value
4. If no option is highlighted but some value... | _getHint | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
componentWillMount() {
const id = uniqueId();
this._styleId = `style-id${id}`;
this._caretStyleId = `caretStyle-id${id}`;
updatePseudoClassStyle(this._styleId, this._caretStyleId, this.props);
} | Generates the style-id & inject the focus & hover style. | componentWillMount | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
componentWillReceiveProps(properties) {
const newState = {
wrapperProps: sanitizeWrapperProps(properties.wrapperProps),
inputProps: sanitizeInputProps(properties),
caretProps: sanitizeCaretProps(properties.caretProps),
menuProps: sanitizeMenuProps(properties.menuProps),
};
if (has(p... | Generates the style-id & inject the focus & hover style. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
componentWillUnmount() {
removeAllStyles([this._styleId, this._caretStyleId]);
} | Remove a component's associated styles whenever it gets removed from the DOM. | componentWillUnmount | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_onArrowUpKeyDown() {
if (this.filteredOptions.length > 0) {
let index = this.filteredOptions.length - 1;
if (this.state.focusedOptionIndex) {
index = this.state.focusedOptionIndex - 1;
}
this.setState({
focusedOptionIndex: index,
});
}
} | Highlight previous option when arrowUp key is pressed.
Highlight last option if currently first option is focused. | _onArrowUpKeyDown | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_onEnterOrTabKeyDown() {
if (this.state.focusedOptionIndex >= 0) {
this._triggerChange(this.filteredOptions[this.state.focusedOptionIndex].props.value);
}
} | Update value of Input box to the value of highlighted option. | _onEnterOrTabKeyDown | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_findMatch(value) {
return find(this.filteredOptions, (entry) => entry.props.value === value);
} | The function will return options (if any) who's value is same as value of the combo-box input. | _findMatch | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_triggerChange(value) {
if (has(this.props, 'valueLink')) {
this.props.valueLink.requestChange(value);
this.setState({
isOpen: false,
focusedOptionIndex: undefined,
});
} else if (has(this.props, 'value')) {
this.setState({
isOpen: false,
focusedOptionInde... | The function is called when user selects an option. Function will do following:
1. Close the options
2. Change value of input depending on whether its has value, defaultValue or valueLink property
3. Call onUpdate props function | _triggerChange | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_getValueForIndex(index) {
return this.filteredOptions[index].props.value;
} | Returns the value of the child with a certain index. | _getValueForIndex | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
_userUpdateValue(value) {
if (has(this.props, 'valueLink')) {
this.props.valueLink.requestChange(value);
this.setState({
isOpen: true,
focusedOptionIndex: undefined,
});
} else if (has(this.props, 'value')) {
this.setState({
isOpen: true,
focusedOptionInde... | The function is called when user inputs a value in the input box. This can be done by:
1. typing/ pasting value into input box
2. pressing arrowRight key when there is some hint in the input box
Function will do following:
1. Open the options
2. Change value of input depending on whether its has value, defaultValue or... | _userUpdateValue | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
static filterOptions(inputValue, properties) { /* eslint react/sort-comp:0*/
let filteredOptions = [];
if (!isEmpty(properties.children)) {
if (inputValue) {
filteredOptions = filterReactChildren(properties.children, (entry) => (
properties.filterFunc(inputValue, entry.props.value)
... | Function to filter options using input value. | filterOptions | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
render() {
let inputStyle = {
...style.style,
...this.props.style,
};
const hintStyle = {
...style.hintStyle,
...this.props.hintStyle,
};
const wrapperStyle = {
...style.wrapperStyle,
...this.props.wrapperStyle,
};
const menuStyle = {
...style.menuSt... | Function to filter options using input value. | render | javascript | nikgraf/belle | src/components/ComboBox.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBox.js | MIT |
render() {
return (
<li
onClick={ this._onClick }
onMouseEnter={ this._onMouseEnter }
onMouseLeave={ this._onMouseLeave }
onMouseDown={ this._onMouseDown }
onTouchStart={ this._onTouchStart }
onTouchEnd={ this._onTouchEnd }
onTouchCancel={ this._onTouchC... | Belle internal component to wrap an Option in a ComboBox.
This component exists to avoid binding functions in JSX. | render | javascript | nikgraf/belle | src/components/ComboBoxItem.js | https://github.com/nikgraf/belle/blob/master/src/components/ComboBoxItem.js | MIT |
function sanitizeWrapperProps(properties) {
return omit(properties, Object.keys(datePickerPropTypes));
} | Returns an object with properties that are relevant for the wrapping div of the date picker. | sanitizeWrapperProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeEmptyDayProps(properties) {
return omit(properties, [
'key',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeEmptyDayProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeDisabledDayProps(properties) {
return omit(properties, [
'key',
'onMouseEnter',
'onMouseLeave',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeDisabledDayProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeDayProps(properties) {
return omit(properties, [
'key',
'onMouseDown',
'onMouseUp',
'onMouseEnter',
'onMouseLeave',
'onTouchStart',
'onTouchEnd',
'onTouchCancel',
'aria-selected',
'style',
'role',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeDayProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeNavBarProps(properties) {
return omit(properties, [
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeNavBarProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizePrevMonthNavProps(properties) {
return omit(properties, [
'aria-label',
'className',
'onClick',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizePrevMonthNavProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizePrevMonthNavIconProps(properties) {
return omit(properties, [
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizePrevMonthNavIconProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeNextMonthNavProps(properties) {
return omit(properties, [
'aria-label',
'className',
'onClick',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeNextMonthNavProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeNextMonthNavIconProps(properties) {
return omit(properties, [
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeNextMonthNavIconProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeMonthLabelProps(properties) {
return omit(properties, [
'id',
'role',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeMonthLabelProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeDayLabelProps(properties) {
return omit(properties, [
'key',
'role',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeDayLabelProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeWeekHeaderProps(properties) {
return omit(properties, [
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeWeekHeaderProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function sanitizeWeekGridProps(properties) {
return omit(properties, [
'role',
'style',
]);
} | Returns an object with properties that are relevant for day span. | sanitizeWeekGridProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
function updatePseudoClassStyle(pseudoStyleIds, properties, preventFocusStyleForTouchAndClick) {
const styles = [
{
id: pseudoStyleIds.prevMonthNavStyleId,
style: {
...defaultStyle.hoverPrevMonthNavStyle,
...properties.hoverPrevMonthNavStyle,
},
pseudoClass: 'hover',
}... | Injects pseudo classes for styles into the DOM. | updatePseudoClassStyle | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
constructor(properties) {
super(properties);
let selectedDate;
let month;
let year;
if (has(properties, 'valueLink')) {
selectedDate = properties.valueLink.value;
} else if (has(properties, 'value')) {
selectedDate = properties.value;
} else if (has(properties, 'defaultValue')) ... | DatePicker React Component.
This implementation follows the recommendations proposed here:
http://www.w3.org/TR/wai-aria-practices/#datepicker | constructor | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
componentWillMount() {
const id = uniqueId();
this.pseudoStyleIds = {};
this.pseudoStyleIds.styleId = `wrapper-style-id${id}`;
this.pseudoStyleIds.prevMonthNavStyleId = `prevMonthNav-style-id${id}`;
this.pseudoStyleIds.nextMonthNavStyleId = `nextMonthNav-style-id${id}`;
updatePseudoClassStyle(th... | Generates the style-id based on React's unique DOM node id.
Calls function to inject the pseudo classes into the dom. | componentWillMount | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
componentWillReceiveProps(properties) {
const newState = {};
if (has(properties, 'valueLink')) {
newState.selectedDate = properties.valueLink.value;
} else if (has(properties, 'value')) {
newState.selectedDate = properties.value;
}
this.setState(newState);
this.localeData = getLoc... | Function will update component state and styles as new props are received. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_triggerSelectDate(day, month, year) {
if (!this.props.disabled && !this.props.readOnly) {
const selectedDate = day ? new Date(year, month, day) : undefined;
if (has(this.props, 'valueLink')) {
this.props.valueLink.requestChange(selectedDate);
} else if (!has(this.props, 'value')) {
... | Depending on whether component is controlled or uncontrolled the function will update this.state.selectedDate.
It will also call props.onUpdate. | _triggerSelectDate | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_triggerToggleDate(date) {
if (!this.props.disabled && !this.props.readOnly) {
let day;
let month;
let year;
if (this.state.selectedDate && date &&
this.state.selectedDate.getDate() === date.getDate() && this.state.selectedDate.getMonth() === date.getMonth() && this.state.selectedD... | Function will select / deselect date passed to it, it is used in case of 'Space' keyDown on a day. | _triggerToggleDate | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_focusOnTheFistDayOfTheMonth() {
this.setState({
focusedDateKey: `${this.state.year}-${this.state.month + 1}-1`,
});
} | Function will select / deselect date passed to it, it is used in case of 'Space' keyDown on a day. | _focusOnTheFistDayOfTheMonth | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_focusOnFallbackDay() {
if (this.state.lastHoveredDay) {
this.setState({
focusedDateKey: this.state.lastHoveredDay,
});
} else {
this._focusOnTheFistDayOfTheMonth();
}
} | Function will select / deselect date passed to it, it is used in case of 'Space' keyDown on a day. | _focusOnFallbackDay | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_focusOtherDay(days) {
const focusedDate = getDateForDateKey(this.state.focusedDateKey);
const currentMonth = focusedDate.getMonth();
const nextFocusedDate = getDateForDateKey(this.state.focusedDateKey);
nextFocusedDate.setDate(nextFocusedDate.getDate() + days);
const nextFocusedDateKey = convertDa... | The function is mainly used when some day is focused and Arrow keys are pressed to navigate to some other day.
days is the number of days by which focused should be moved ahead or behind. | _focusOtherDay | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_decreaseMonthYear() {
let newMonth;
let newYear;
if (this.state.month === 0) {
newMonth = 11;
newYear = this.state.year - 1;
} else {
newMonth = this.state.month - 1;
newYear = this.state.year;
}
this.setState({
month: newMonth,
year: newYear,
focusedD... | The function will decrease current month in state. It will also call props.onMonthUpdate. | _decreaseMonthYear | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_increaseMonthYear() {
let newMonth;
let newYear;
if (this.state.month === 11) {
newMonth = 0;
newYear = this.state.year + 1;
} else {
newMonth = this.state.month + 1;
newYear = this.state.year;
}
this.setState({
month: newMonth,
year: newYear,
focusedD... | The function will increase current month in state. It will also call props.onMonthUpdate. | _increaseMonthYear | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_isWithinMinAndMax(date) {
return !(this.props.min && date < this.props.min ||
this.props.max && date > this.props.max);
} | The function will increase current month in state. It will also call props.onMonthUpdate. | _isWithinMinAndMax | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_renderPrevMonthNav() {
const prevMonthNavStyle = {
...defaultStyle.prevMonthNavStyle,
...this.props.prevMonthNavStyle,
};
const prevMonthNavIconStyle = {
...defaultStyle.prevMonthNavIconStyle,
...this.props.prevMonthNavIconStyle,
};
let className = this.pseudoStyleIds.prev... | The function will increase current month in state. It will also call props.onMonthUpdate. | _renderPrevMonthNav | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_renderNextMonthNav() {
const nextMonthNavStyle = {
...defaultStyle.nextMonthNavStyle,
...this.props.nextMonthNavStyle,
};
const nextMonthNavIconStyle = {
...defaultStyle.nextMonthNavIconStyle,
...this.props.nextMonthNavIconStyle,
};
let className = this.pseudoStyleIds.next... | The function will increase current month in state. It will also call props.onMonthUpdate. | _renderNextMonthNav | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_renderNavBar() {
const navBarStyle = {
...defaultStyle.navBarStyle,
...this.props.navBarStyle,
};
const monthLabelStyle = {
...defaultStyle.monthLabelStyle,
...this.props.monthLabelStyle,
};
return (
<div
style={ navBarStyle }
{ ...this.navBarProps }
... | Function will return jsx for rendering the nav bar for calendar.
Depending on following rules it will apply styles to prevMonthNav and nextMonthNav:
1. If disabled hide navs
2. If active apply activeStyles | _renderNavBar | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_renderWeekHeader() {
const weekHeaderStyle = {
...defaultStyle.weekHeaderStyle,
...this.props.weekHeaderStyle,
};
let dayLabelStyle = {
...defaultStyle.dayLabelStyle,
...this.props.dayLabelStyle,
};
if (this.props.disabled) {
dayLabelStyle = {
...dayLabelStyle... | Function will return jsx for rendering the week header for calendar.
Disabled styles will be applied for disabled date-picker.
Day headers will be rendered using locale information. | _renderWeekHeader | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
_renderDay(currentDate, index) {
const day = currentDate.getDate();
const month = currentDate.getMonth();
const year = currentDate.getFullYear();
const isOtherMonth = month !== this.state.month;
const dateKey = convertDateToDateKey(currentDate);
const isDisabledDay = !this._isWithinMinAndMax(cur... | Function will return jsx for rendering the a day.
It will apply various styles in sequence as below (styles will be additive):
1. If component is readOnly apply readOnly styles
2. If component is disabled apply disabled styles
- If component is disabled and hovered apply disableHover styles
3. If day is weekend appl... | _renderDay | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
render() {
let style = {
...defaultStyle.style,
...this.props.style,
};
if (this.props.readOnly) {
style = {
...style,
...defaultStyle.readOnlyStyle,
...this.props.readOnlyStyle,
};
}
if (this.props.disabled) {
style = {
...style,
... | Function will render:
- main calendar component
- call methods to render navBar and week header
- get array of weeks in a month and for each day in the week call method to render day
It will apply styles sequentially according to Wrapper according to following rules:
1. If component is readOnly apply readOnlyStyle
2. ... | render | javascript | nikgraf/belle | src/components/DatePicker.js | https://github.com/nikgraf/belle/blob/master/src/components/DatePicker.js | MIT |
render() {
return (
<span
style={ this.props.style }
onMouseEnter={ this._onMouseEnter }
onMouseLeave={ this._onMouseLeave }
onMouseDown={ this._onMouseDown }
onMouseUp={ this._onMouseUp }
onTouchStart={ this._onTouchStart }
onTouchEnd={ this._onTouchEnd... | Belle internal component to wrap a Day in a DatePicker.
This component exists to avoid binding functions in JSX. | render | javascript | nikgraf/belle | src/components/Day.js | https://github.com/nikgraf/belle/blob/master/src/components/Day.js | MIT |
render() {
return (
<span
style={ this.props.style }
onMouseEnter={ this._onDayMouseEnter }
onMouseLeave={ this._onDayMouseLeave }
{...this.props.disabledDayProps}
>
{ this.props.children }
</span>
);
} | Belle internal component to wrap a DisabledDay in a DatePicker.
This component exists to avoid binding functions in JSX. | render | javascript | nikgraf/belle | src/components/DisabledDay.js | https://github.com/nikgraf/belle/blob/master/src/components/DisabledDay.js | MIT |
function sanitizeChildProps(properties) {
return omit(properties, Object.keys(optionPropTypes));
} | Returns an object with properties that are relevant for the wrapping div. | sanitizeChildProps | javascript | nikgraf/belle | src/components/Option.js | https://github.com/nikgraf/belle/blob/master/src/components/Option.js | MIT |
constructor(properties) {
super(properties);
this.state = {
childProps: sanitizeChildProps(properties),
};
} | Option component.
This component should be used together with Belle's Select. | constructor | javascript | nikgraf/belle | src/components/Option.js | https://github.com/nikgraf/belle/blob/master/src/components/Option.js | MIT |
componentWillReceiveProps(properties) {
this.setState({ childProps: sanitizeChildProps(properties) });
} | Update the childProps based on the updated properties passed to the
Option. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/Option.js | https://github.com/nikgraf/belle/blob/master/src/components/Option.js | MIT |
render() {
let optionStyle;
if (this.props._isDisplayedAsSelected) {
optionStyle = {
...style.selectStyle,
...this.props.selectStyle,
};
if (this.context.isDisabled) {
optionStyle = {
...optionStyle,
...style.disabledSelectStyle,
...this.p... | Update the childProps based on the updated properties passed to the
Option. | render | javascript | nikgraf/belle | src/components/Option.js | https://github.com/nikgraf/belle/blob/master/src/components/Option.js | MIT |
function sanitizeChildProps(properties) {
return omit(properties, Object.keys(placeholderPropTypes));
} | Returns an object with properties that are relevant for the wrapping div. | sanitizeChildProps | javascript | nikgraf/belle | src/components/Placeholder.js | https://github.com/nikgraf/belle/blob/master/src/components/Placeholder.js | MIT |
constructor(properties) {
super(properties);
this.state = {
childProps: sanitizeChildProps(properties),
};
} | Placeholder component.
This component should be used together with Belle's Select. | constructor | javascript | nikgraf/belle | src/components/Placeholder.js | https://github.com/nikgraf/belle/blob/master/src/components/Placeholder.js | MIT |
componentWillReceiveProps(properties) {
this.setState({ childProps: sanitizeChildProps(properties) });
} | Update the childProps based on the updated properties passed to the
Placeholder. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/Placeholder.js | https://github.com/nikgraf/belle/blob/master/src/components/Placeholder.js | MIT |
render() {
let computedStyle = {
...style.style,
...this.props.style,
};
if (this.props._isDisabled) {
computedStyle = {
...computedStyle,
...style.disabledStyle,
...this.props.disabledStyle,
};
}
return (
<div style={ computedStyle } {...this.s... | Update the childProps based on the updated properties passed to the
Placeholder. | render | javascript | nikgraf/belle | src/components/Placeholder.js | https://github.com/nikgraf/belle/blob/master/src/components/Placeholder.js | MIT |
function sanitizeWrapperProps(properties) {
return omit(properties, Object.keys(ratingPropTypes));
} | sanitize properties for the wrapping div. | sanitizeWrapperProps | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
function sanitizeCharacterProps(properties) {
return omit(properties, [
'data-belle-value',
'style',
]);
} | sanitize properties for the character span. | sanitizeCharacterProps | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
function updatePseudoClassStyle(ratingWrapperStyleId, properties, preventFocusStyleForTouchAndClick) {
let ratingFocusStyle;
if (preventFocusStyleForTouchAndClick) {
ratingFocusStyle = { outline: 0 };
} else {
ratingFocusStyle = {
...style.focusStyle,
...properties.focusStyle,
};
}
co... | Injects pseudo classes for styles into the DOM. | updatePseudoClassStyle | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
constructor(properties) {
super(properties);
let value;
if (has(properties, 'valueLink')) {
value = properties.valueLink.value;
} else if (has(properties, 'value')) {
value = properties.value;
} else if (has(properties, 'defaultValue')) {
value = properties.defaultValue;
}
... | Rating component
The component leverages 5 characters (by default stars) to allow the user to
to rate. | constructor | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
componentWillMount() {
const id = uniqueId();
this.ratingWrapperStyleId = `rating-wrapper-style-id${id}`;
updatePseudoClassStyle(this.ratingWrapperStyleId, this.props, this.preventFocusStyleForTouchAndClick);
if (canUseDOM) {
this.mouseUpOnDocumentCallback = this._onMouseUpOnDocument;
docum... | Apply pseudo class styling to the wrapper div. | componentWillMount | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
componentWillReceiveProps(properties) {
const newState = {
wrapperProps: sanitizeWrapperProps(properties),
characterProps: sanitizeCharacterProps(properties.characterProps),
};
if (properties.valueLink) {
newState.value = properties.valueLink.value;
} else if (properties.value) {
... | Apply pseudo class styling to the wrapper div. | componentWillReceiveProps | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
componentWillUnmount() {
removeStyle(this.ratingWrapperStyleId);
if (canUseDOM) {
document.removeEventListener('mouseup', this.mouseUpOnDocumentCallback);
}
} | Removes pseudo classes from the DOM once component gets removed. | componentWillUnmount | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
_getCurrentValue() {
let value;
if (this.state.focusedValue !== undefined) {
value = this.state.focusedValue;
} else {
value = (this.state.value) ? this.state.value : 0;
}
return value;
} | Returns current value of rating to be displayed on the component | _getCurrentValue | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
_triggerComponentUpdateOnTouchMove(touches) {
const touchedElement = document.elementFromPoint(touches.clientX, touches.clientY);
const value = Number(touchedElement.getAttribute('data-belle-value'));
if (value && this.state.focusedValue !== value) {
this.setState({
focusedValue: value,
... | The function will be passed to requestAnimationFrame for touchMove | _triggerComponentUpdateOnTouchMove | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
_triggerComponentUpdate(value) {
if (has(this.props, 'valueLink')) {
this.props.valueLink.requestChange(value);
this.setState({
focusedValue: undefined,
isActive: false,
});
} else if (has(this.props, 'value')) {
this.setState({
focusedValue: undefined,
is... | update component when component is clicked, touch ends, enter or space key are hit
different update logic will apply depending on whether component has property defaultValue, value or valueLink specified | _triggerComponentUpdate | javascript | nikgraf/belle | src/components/Rating.js | https://github.com/nikgraf/belle/blob/master/src/components/Rating.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.