-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Criando o filtro para number.
- Loading branch information
Showing
8 changed files
with
113 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react"; | ||
import { handleNumber } from "../../utils"; | ||
import { handleGetValueNumber } from "../function/handle"; | ||
import { InputFilterCoreProps, InputFilterOptionsMap } from "../types"; | ||
|
||
/** | ||
* Core - `Number` | ||
* Campo do filtro tipo numero | ||
*/ | ||
export function Number<T extends keyof InputFilterOptionsMap>(props: InputFilterCoreProps<T>) { | ||
return ( | ||
<input className="form-control input-filter-field" | ||
disabled={props.disabled} | ||
id={(props.id ?? "input-filter") + "-number"} | ||
name={(props.name ?? "input-filter") + "-number"} | ||
placeholder={props.placeholder} | ||
value={handleGetValueNumber(props.value, props.options ?? "")} | ||
onChange={event => props.onChange(handleNumber(event.target.value, "decimal") + props.select)}/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Formata um valor numérico para o formato decimal ou monetário. | ||
* | ||
* @param valor - O valor a ser formatado. | ||
* @param format - O formato desejado: "money" para monetário ou "decimal" para decimal. | ||
* @returns O valor formatado como string. | ||
*/ | ||
export function handleNumber( | ||
valor: string, | ||
format: "money" | "decimal" = "decimal" | ||
): string { | ||
let value = valor.replace(/[^0-9.,]/g, ""); | ||
if (format === "decimal") { | ||
return value.replace(",", ".").replace(/(\..*)\./g, "$1"); | ||
} | ||
return parseFloat(value.replace(",", ".")).toLocaleString("pt-BR", { | ||
style: "currency", | ||
currency: "BRL" | ||
}).replace(".", " "); | ||
} | ||
|
||
/** | ||
* Formata um valor de string para o formato de horas (HH:MM). | ||
* | ||
* @param valor - O valor a ser formatado. | ||
* @returns O valor formatado como string no formato de horas. | ||
*/ | ||
export function handleHours(valor: string): string { | ||
let value = valor.replace(/[^\d.]/g, ""); | ||
const parts = value.split("."); | ||
|
||
if (parts.length > 1) { | ||
parts[1] = parts[1].substring(0, 2); | ||
} | ||
|
||
value = parts.join("."); | ||
if (value.length > 2) { | ||
value = value.substring(0, value.length - 2) + ":" + value.substring(value.length - 2); | ||
} | ||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters