date-fns/locale#ptBR TypeScript Examples
The following examples show how to use
date-fns/locale#ptBR.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From houston with MIT License | 5 votes |
function ThemeProvider({
theme = defaultTheme,
children,
disableCssBaseline,
disabledFontBase,
disableToast
}: IThemeProviderProps) {
const [muiTheme] = React.useState(() => generateTheme(theme));
const [styleContent] = React.useState(() => ({
__html: `
form { width: 100%; }
a { text-decoration: none; }
.houston-icon { line-height: 0; }
${
!disabledFontBase &&
`
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700');
body {
font-family: ${theme.font.family.base};
font-size: ${theme.font.size.xs};
-webkit-font-smoothing: auto;
}
`
}
`
}));
React.useEffect(() => setCurrentTheme(theme), [theme]);
return (
<StyledEngineProvider injectFirst>
<MUIThemeProvider theme={muiTheme}>
<LocalizationProvider locale={ptBR} dateAdapter={AdapterDateFns}>
<PopoverRoot>
<style dangerouslySetInnerHTML={styleContent} />
{!disableToast && <ToastContainer />}
{!disableCssBaseline && <CssBaseline />}
{children}
</PopoverRoot>
</LocalizationProvider>
</MUIThemeProvider>
</StyledEngineProvider>
);
}
Example #2
Source File: index.tsx From space-traveling with MIT License | 4 votes |
export default function Home({
postsPagination,
preview,
}: HomeProps): ReactElement {
function getReadTime(item: Post): number {
const totalWords = item.data.content.reduce((total, contentItem) => {
total += contentItem.heading.split(' ').length;
const words = contentItem.body.map(i => i.text.split(' ').length);
words.map(word => (total += word));
return total;
}, 0);
return Math.ceil(totalWords / 200);
}
const formattedPost = postsPagination.results.map(post => {
const readTime = getReadTime(post);
return {
...post,
data: {
...post.data,
readTime,
},
first_publication_date: format(
new Date(post.first_publication_date),
'dd MMM yyyy',
{
locale: ptBR,
}
),
};
});
const [posts, setPosts] = useState<Post[]>(formattedPost);
const [nextPage, setNextPage] = useState(postsPagination.next_page);
const [currentPage, setCurrentPage] = useState(1);
async function handleNextPage(): Promise<void> {
if (currentPage !== 1 && nextPage === null) {
return;
}
const postsResults = await fetch(`${nextPage}`).then(response =>
response.json()
);
setNextPage(postsResults.next_page);
setCurrentPage(postsResults.page);
const newPosts = postsResults.results.map((post: Post) => {
const readTime = getReadTime(post);
return {
uid: post.uid,
first_publication_date: format(
new Date(post.first_publication_date),
'dd MMM yyyy',
{
locale: ptBR,
}
),
data: {
title: post.data.title,
subtitle: post.data.subtitle,
author: post.data.author,
readTime,
},
};
});
setPosts([...posts, ...newPosts]);
}
return (
<>
<Head>
<title>Home | spacetraveling</title>
</Head>
<main className={commonStyles.container}>
<Header />
<div className={styles.posts}>
{posts.map(post => (
<Link href={`/post/${post.uid}`} key={post.uid}>
<a className={styles.post}>
<strong>{post.data.title}</strong>
<p>{post.data.subtitle}</p>
<ul>
<li>
<FiCalendar />
{post.first_publication_date}
</li>
<li>
<FiUser />
{post.data.author}
</li>
<li>
<FiClock />
{`${post.data.readTime} min`}
</li>
</ul>
</a>
</Link>
))}
{nextPage && (
<button type="button" onClick={handleNextPage}>
Carregar mais posts
</button>
)}
</div>
{preview && (
<aside>
<Link href="/api/exit-preview">
<a className={commonStyles.preview}>Sair do modo Preview</a>
</Link>
</aside>
)}
</main>
</>
);
}
Example #3
Source File: [slug].tsx From space-traveling with MIT License | 4 votes |
export default function Post({
post,
navigation,
preview,
}: PostProps): JSX.Element {
const router = useRouter();
if (router.isFallback) {
return <h1>Carregando...</h1>;
}
const totalWords = post.data.content.reduce((total, contentItem) => {
total += contentItem.heading.split(' ').length;
const words = contentItem.body.map(item => item.text.split(' ').length);
words.map(word => (total += word));
return total;
}, 0);
const readTime = Math.ceil(totalWords / 200);
const formatedDate = format(
new Date(post.first_publication_date),
'dd MMM yyyy',
{
locale: ptBR,
}
);
const isPostEdited =
post.first_publication_date !== post.last_publication_date;
let editionDate;
if (isPostEdited) {
editionDate = format(
new Date(post.last_publication_date),
"'* editado em' dd MMM yyyy', às' H':'m",
{
locale: ptBR,
}
);
}
return (
<>
<Head>
<title>SpaceTraveling | {post.data.title}</title>
</Head>
<Header />
<img src={post.data.banner.url} alt="imagem" className={styles.banner} />
<main className={commonStyles.container}>
<div className={styles.post}>
<div className={styles.postTop}>
<h1>{post.data.title}</h1>
<ul>
<li>
<FiCalendar />
{formatedDate}
</li>
<li>
<FiUser />
{post.data.author}
</li>
<li>
<FiClock />
{`${readTime} min`}
</li>
</ul>
<span>{isPostEdited && editionDate}</span>
</div>
{post.data.content.map(content => {
return (
<article key={content.heading}>
<h2>{content.heading}</h2>
<div
className={styles.postContent}
dangerouslySetInnerHTML={{
__html: RichText.asHtml(content.body),
}}
/>
</article>
);
})}
</div>
<section className={`${styles.navigation} ${commonStyles.container}`}>
{navigation?.prevPost.length > 0 && (
<div>
<h3>{navigation.prevPost[0].data.title}</h3>
<Link href={`/post/${navigation.prevPost[0].uid}`}>
<a>Post anterior</a>
</Link>
</div>
)}
{navigation?.nextPost.length > 0 && (
<div>
<h3>{navigation.nextPost[0].data.title}</h3>
<Link href={`/post/${navigation.nextPost[0].uid}`}>
<a>Próximo post</a>
</Link>
</div>
)}
</section>
<Comments />
{preview && (
<aside>
<Link href="/api/exit-preview">
<a className={commonStyles.preview}>Sair do modo Preview</a>
</Link>
</aside>
)}
</main>
</>
);
}