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

feat(react): elementPredicate can accept asynchronous predicate #502

Merged
merged 6 commits into from
Sep 14, 2023

Conversation

nsbarsukov
Copy link
Member

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring
  • Code style update
  • Build or CI related changes
  • Documentation content changes

What is the new behavior?

import type {MaskitoElementPredicateAsync} from '@maskito/core';
import {maskitoTimeOptionsGenerator} from '@maskito/kit';
import {useMaskito} from '@maskito/react';
import {forwardRef} from 'react';

const options = maskitoTimeOptionsGenerator({
    mode: 'HH:MM',
});

const elementPredicate: MaskitoElementPredicateAsync = host =>
    new Promise(resolve => {
        setTimeout(() => {
            resolve(host.querySelector('input.real-input')!);
        }, 2_000);
    });

const hiddenInputStyles = {
    display: 'none',
};

export const AwesomeInput = forwardRef<HTMLInputElement>((props, ref) => (
    <div ref={ref}>
        <input style={hiddenInputStyles} />
        <input
            className="real-input"
            {...props}
        />
        <input style={hiddenInputStyles} />
    </div>
));

export const App = () => {
    const inputRef = useMaskito({options, elementPredicate});

    return (
        <AwesomeInput
            ref={inputRef}
            placeholder="React async predicate"
        />
    );
};

@github-actions
Copy link
Contributor

github-actions bot commented Sep 12, 2023

Visit the preview URL for this PR (updated for commit 2cd4705):

https://maskito--pr502-react-async-predicat-x1q8bif6.web.app

(expires Fri, 15 Sep 2023 10:09:42 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 61e4dea776cbea516b68c67840913d2edd88bb90

@nsbarsukov nsbarsukov marked this pull request as ready for review September 12, 2023 14:54
@github-actions github-actions bot added the ready to merge ready label Sep 14, 2023
@nsbarsukov nsbarsukov merged commit 4bbf758 into main Sep 14, 2023
22 checks passed
@nsbarsukov nsbarsukov deleted the react-async-predicate branch September 14, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants