Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mantinedev/mantine
Browse files Browse the repository at this point in the history
  • Loading branch information
rtivital committed Mar 24, 2022
2 parents d200840 + b8eb628 commit 419dcc8
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/src/docs/dates/date-picker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ function Demo() {
`dateParser` function should always return Date object.
If parsed date is invalid when input is blurred value will be restored to last valid value.

Note that if you use the default dayjs parser, you will need to import and configure the
`customParseFormat` dayjs plugin:

```tsx
import customParseFormat from 'dayjs/plugin/customParseFormat';
dayjs.extend(customParseFormat);
```

## Exclude dates

To exclude dates set `excludeDate` prop with function that receives date as an argument and returns
Expand Down
5 changes: 3 additions & 2 deletions src/mantine-core/src/components/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useRef, forwardRef } from 'react';
import { useMergedRef, assignRef, clamp } from '@mantine/hooks';
import { useMergedRef, assignRef, clamp, useOs } from '@mantine/hooks';
import { DefaultProps, ClassNames, useMantineDefaultProps } from '@mantine/styles';
import { getInputMode } from '../../utils';
import { TextInput } from '../TextInput/TextInput';
import { InputStylesNames } from '../Input/Input';
import { InputWrapperStylesNames } from '../InputWrapper/InputWrapper';
Expand Down Expand Up @@ -369,7 +370,7 @@ export const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
size={size}
styles={styles}
classNames={classNames}
inputMode={Number.isInteger(step) && precision === 0 ? 'numeric' : 'decimal'}
inputMode={getInputMode(step, precision, useOs())}
__staticSelector="NumberInput"
/>
);
Expand Down
14 changes: 14 additions & 0 deletions src/mantine-core/src/utils/get-input-mode/get-input-mode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getInputMode } from './get-input-mode';

describe('@mantine/core/utils/get-input-mode', () => {
it('gets input mode', () => {
expect(getInputMode(0.1, 0.1, 'android')).toBe('decimal');
expect(getInputMode(1, 0, 'android')).toBe('numeric');
expect(getInputMode(-0.1, 0.1, 'android')).toBe('decimal');
expect(getInputMode(-1, 0, 'android')).toBe('decimal');
expect(getInputMode(0.1, 0.1, 'ios')).toBe('decimal');
expect(getInputMode(1, 0, 'ios')).toBe('numeric');
expect(getInputMode(-0.1, 0.1, 'ios')).toBe('text');
expect(getInputMode(-1, 0, 'ios')).toBe('text');
});
});
19 changes: 19 additions & 0 deletions src/mantine-core/src/utils/get-input-mode/get-input-mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { OS } from '@mantine/hooks';

export const getInputMode = (
step: number,
precision: number,
os: OS
): 'none' | 'text' | 'search' | 'email' | 'tel' | 'url' | 'numeric' | 'decimal' => {
if (Number.isInteger(step) && step >= 0 && precision === 0) return 'numeric';
if (!Number.isInteger(step) && step >= 0 && precision !== 0) return 'decimal';
if (Number.isInteger(step) && step < 0 && precision === 0) {
if (os === 'ios') return 'text';
return 'decimal';
}
if (!Number.isInteger(step) && step < 0 && precision !== 0) {
if (os === 'ios') return 'text';
return 'decimal';
}
return 'numeric';
};
1 change: 1 addition & 0 deletions src/mantine-core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { filterFalsyChildren } from './filter-falsy-children/filter-falsy-childr
export { groupOptions, getGroupedOptions } from './group-options/group-options';
export { getContextItemIndex } from './get-context-item-index/get-context-item-index';
export { createUseContext } from './create-use-context/create-use-context';
export { getInputMode } from './get-input-mode/get-input-mode';
6 changes: 3 additions & 3 deletions src/mantine-demos/src/demos/packages/Badge/configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export const configurator: MantineDemo = {
{
name: 'variant',
type: 'select',
initialValue: 'filled',
defaultValue: 'filled',
initialValue: 'light',
defaultValue: 'light',
data: [
{ value: 'light', label: 'Light' },
{ value: 'filled', label: 'Filled' },
{ value: 'outline', label: 'Outline' },
{ value: 'light', label: 'Light' },
{ value: 'dot', label: 'Dot' },
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/mantine-demos/src/demos/packages/Stepper/usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Demo() {
return (
<>
<Stepper active={active} onStepClick={setActive} breakpoint="sm">
<Stepper.Step label="Fist step" description="Create an account">
<Stepper.Step label="First step" description="Create an account">
Step 1 content: Create an account
</Stepper.Step>
<Stepper.Step label="Second step" description="Verify email">
Expand Down
12 changes: 7 additions & 5 deletions src/mantine-spotlight/src/SpotlightProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useRef } from 'react';
import { useDisclosure } from '@mantine/hooks';
import { useDidUpdate, useDisclosure } from '@mantine/hooks';
import { useActionsState } from './use-actions-state/use-actions-state';
import { useSpotlightShortcuts } from './use-spotlight-shortcuts/use-spotlight-shortcuts';
import { Spotlight, InnerSpotlightProps } from './Spotlight/Spotlight';
Expand Down Expand Up @@ -42,10 +42,12 @@ export function SpotlightProvider({
}: SpotlightProviderProps) {
const timeoutRef = useRef<number>(-1);
const [query, setQuery] = useState('');
const [actions, { registerActions, removeActions, triggerAction }] = useActionsState(
initialActions,
query
);
const [actions, { registerActions, updateActions, removeActions, triggerAction }] =
useActionsState(initialActions, query);

useDidUpdate(() => {
updateActions(initialActions);
}, [initialActions]);

const handleQueryChange = (value: string) => {
setQuery(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ describe('@mantine/spotlight/use-actions-state', () => {
]);
});

it('update actions', () => {
const hook = renderHook(() => useActionsState(ACTIONS, ''));
act(() =>
hook.result.current[1].updateActions([
{ id: 'action-4', title: 'Action 4', onTrigger },
{ id: 'action-5', title: 'Action 5', onTrigger },
])
);

expect(hook.result.current[0]).toStrictEqual([
{ id: 'action-4', title: 'Action 4', onTrigger },
{ id: 'action-5', title: 'Action 5', onTrigger },
]);
});

it('generates unique ids for newly registered actions if action.id is not provided', () => {
const hook = renderHook(() => useActionsState(ACTIONS, ''));
act(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export function useActionsState(
}
}, [query]);

const updateActions = (payload: SpotlightAction[] | ((query: string) => SpotlightAction[])) =>
setActions(prepareActions(typeof payload === 'function' ? payload(query) : payload));

const registerActions = (payload: SpotlightAction[]) =>
setActions((current) => prepareActions([...current, ...payload]));

Expand All @@ -54,6 +57,7 @@ export function useActionsState(
actions,
{
registerActions,
updateActions,
removeActions,
triggerAction,
},
Expand Down

0 comments on commit 419dcc8

Please sign in to comment.