Import Arabic font to React Material Theme - html

I need to use Noto Sans Arabic font in my React material UI theme.
The theme is working well, overrides are working too.
I have tried React Material UI docs to import my fonts like in react-material documentation, but it doesn't work:
import notoArabic from '../static/fonts/NotoSansArabic-Regular.ttf'
....
const arabic = {
fontFamily: 'Noto Sans Arabic',
fontStyle: 'regular',
fontDisplay: 'swap',
fontWeight: 400,
src: `
local('Noto Sans Arabic'),
local('Noto Sans Arabic-Regular'),
url(${notoArabic}) format('ttf')
`,
unicodeRange:
'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF',
};
...
overrides: {
MuiCssBaseline: {
'#global': {
'#font-face': [arabic],
},
},
...
I expect that the font will be imported and work.
I have any errors, and can see font-family: Noto Sans Arabic; in my browser. But it doesn't work

I'm Persian and our language fonts very very look like Arabic fonts. for my project, I create a separated file, and I named it globalStyles.js:
import { createStyles } from '#material-ui/core';
import yekanRegularTtf from '../app/assets/font/iranyekanwebregular.ttf';
import yekanRegularWoff from '../app/assets/font/iranyekanwebregular.woff';
import yekanRegularWoff2 from '../app/assets/font/iranyekanwebregular.woff2';
import yekanBoldTtf from '../app/assets/font/iranyekanwebbold.ttf';
import yekanBoldWoff from '../app/assets/font/iranyekanwebbold.woff';
import yekanBoldWoff2 from '../app/assets/font/iranyekanwebbold.woff2';
const globalStyles = ({ spacing, typography, colors }) =>
createStyles({
'#global': {
'#font-face': [
{
fontFamily: 'IRANYekan',
fontStyle: 'normal',
fontWeight: 400,
src: `url(${yekanRegularWoff2}) format('woff2')`,
fallbacks: {
src: [
`url(${yekanRegularWoff})`,
`url(${yekanRegularTtf}) format('truetype')`,
],
},
},
{
fontFamily: 'IRANYekan',
fontStyle: 'normal',
fontWeight: 700,
src: `url(${yekanBoldWoff2}) format('woff2')`,
fallbacks: {
src: [
`url(${yekanBoldWoff})`,
`url(${yekanBoldTtf}) format('truetype')`,
],
},
},
],
html: {
lineHeight: '1.5',
WebkitTextSizeAdjust: '100%',
},
'*': {
transition: 'opacity 1s cubic-bezier(0.4, 0, 0.2, 1)',
fontFamily: "'IRANYekan', sans-serif, Arial",
boxSizing: 'border-box',
'&:after, &:before': {
fontFamily: "'IRANYekan', sans-serif, Arial",
boxSizing: 'border-box',
},
'&[type="checkbox"], &[type="radio"]': {
boxSizing: 'border-box',
padding: '0',
},
'&[type="number"]': {
'&::-webkit-inner-spin-button, &::-webkit-outer-spin-button': {
height: 'auto',
},
},
'&[type="search"]': {
WebkitAppearance: 'textfield',
outlineOffset: -2,
'&::-webkit-search-decoration': {
WebkitAppearance: 'none',
},
},
'&[hidden]': {
display: 'none',
},
'&::-webkit-file-upload-button': {
WebkitAppearance: 'button',
font: 'inherit',
},
},
body: {
fontFamily: "'IRANYekan', sans-serif, Arial",
lineHeight: '1.38',
margin: 0,
},
'#react-view': {},
'h1, h2, h3, h4, h5, h6': {
margin: [[0, 0, spacing.margin]],
lineHeight: '1.3',
letterSpacing: 0,
textTransform: 'none',
color: colors.black,
display: 'block',
fontFamily: "'IRANYekan', sans-serif, Arial",
},
h1: {
fontSize: typography.fontSize * 1.4,
},
h2: {
fontSize: typography.fontSize * 1.2,
},
h3: {
fontSize: typography.fontSize,
},
h4: {
fontSize: typography.fontSize,
},
h5: {
fontSize: typography.fontSize,
},
h6: {
fontSize: typography.fontSize,
},
p: {
display: 'block',
margin: [[0, 0, spacing.margin]],
},
main: {
display: 'block',
},
hr: {
boxSizing: 'content-box',
height: 0,
overflow: 'visible',
},
pre: {
fontSize: '1em',
},
a: {
backgroundColor: 'transparent',
textDecoration: 'none',
},
'b, strong': {
fontWeight: 'bold',
},
small: {
fontSize: '80%',
},
img: {
borderStyle: 'none',
},
button: {
WebkitAppearance: 'button',
},
input: {
overflow: 'visible',
},
'button, input, optgroup, select, textarea': {
fontFamily: 'inherit',
fontSize: '100%',
lineHeight: '1.15',
margin: 0,
},
'button, input': {
overflow: 'visible',
},
'button, select': {
textTransform: 'none',
},
textarea: {
overflow: 'auto',
},
'button, [type="button"], [type="reset"], [type="submit"]': {
WebkitAppearance: 'button',
'&::-moz-focus-inner': {
borderStyle: 'none',
padding: '0',
},
'&:-moz-focusring': {
outline: [[1, 'dotted', 'ButtonText']],
},
},
fieldset: {
padding: '0.35em 0.75em 0.625em',
},
legend: {
boxSizing: 'border-box',
color: 'inherit',
display: 'table',
maxWidth: '100%',
padding: '0',
whiteSpace: 'normal',
},
progress: {
verticalAlign: 'baseline',
},
details: {
display: 'block',
},
summary: {
display: 'list-item',
},
template: {
display: 'none',
},
},
});
export default globalStyles;
And in the top level of my components, I injected to the project root component:
import React from 'react';
import { Provider as ReduxProvider } from 'react-redux';
import { CssBaseline, withStyles } from '#material-ui/core';
import { Helmet } from 'react-helmet';
import SnackBarProvider from './SnackBar';
import globalStyles from '../utils/globalStyles';
import { generalHelmet } from '../utils/helmetConfig';
type AppProviderProps = {
children: any,
store: any,
};
const AppProvider = ({ children, store }: AppProviderProps) => (
<>
<Helmet {...generalHelmet} />
<CssBaseline />
<ReduxProvider store={store}>
<SnackBarProvider>{children}</SnackBarProvider>
</ReduxProvider>
</>
);
export default withStyles(globalStyles)(AppProvider);
Also, in the Webpack configuration file I wrote the font loader just like below:
~~~
const nodeEnv = process.env.NODE_ENV || 'development';
const isDev = nodeEnv === 'development';
const exclude = [/node_modules/, /public/];
const name = isDev ? '[name].[ext]' : '[hash:5].[ext]';
const publicPath = '/assets/';
~~~
module.exports = {
~~~
module: {
rules: [
~~~
{
test: /\.(woff2?|ttf|eot|svg)$/,
exclude,
loader: 'url',
options: { limit: 10240, name, publicPath },
},
And everything works well now. I hope my configuration helps you.

You can try few things as mentioned below to check if you are compiling code properly.
From the related URL which you mentioned to import the font infers that the static folder and above file directory are siblings. Make sure, the related path are same as per root folder.
Also, if you're using webpack to bundle your code, make sure you include ttf file extension and add file-loader module to handle it during compiling.
e.g.
{
test: /\.(png|jpg|gif|svg|ttf|eot|woff)$/,
loader: 'file-loader',
query: {
name: '[name].[ext]?[hash]'
}
},

There are a few possibilities but I would suggest trying loading the same font via your index.css file and check the result, Could it be the location you are referring is not correct or the font isn't present.
Also a file-loader or plugin might be required to render fonts with webpack read: https://chriscourses.com/blog/loading-fonts-webpack

Related

Material-UI NextJS Button Styling Issue

i am having a problem getting the styling right on a couple of buttons in JS, it seems when i add a styling class via className that on first render the formatting works, but on subsequent refreshes it loses its styling. It is only happening on the two individual buttons i have. After troubleshooting for ages, i have found that everything works when i use SX instead of classNames, so if i do this then the refresh works. So in code below one button styles and remains styles, but the second one, refreshing my button class does not? Stumped at this point, i ran through forums and see a lot about NextJs needing some extra config in _document and _app to make it work, but i ran this in from the NextJs Material UI boiler plate from Git so dont think it could be that causing it.
Code:
import React from 'react'
import { AppBar, Toolbar, alpha } from "#mui/material";
import Button from '#mui/material/Button'
import ButtonBase from '#mui/material/ButtonBase';
import { styled } from '#mui/material/styles';
import Typography from '#mui/material/Typography';
import InputBase from '#mui/material/InputBase';
import SearchIcon from '#mui/icons-material/Search';
import AddIcon from '#mui/icons-material/Add';
import { makeStyles } from '#mui/styles'
const useStyles = makeStyles(theme => ({
button: {
...theme.typography.mainmenu,
borderRadius: "40px",
width: "230px",
height: "130px",
marginLeft: "30px",
alignItem: "center",
"&:hover": {
backgroundColor: theme.palette.secondary
},
[theme.breakpoints.down("sm")]: {
width: '100% !important', // Overrides inline-style
height: 100
},
},
}))
/*Image Button Styling Begins*/
const images = [
{
url: '/assets/breakfastMenu.jpg',
title: 'Breakfast',
width: '20%',
},
{
url: '/assets/steak.jpg',
title: 'Mains',
width: '20%',
},
{
url: '/assets/desserts.jpg',
title: 'Desserts',
width: '20%',
},
];
const Image = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
color: theme.palette.common.primary,
}));
const ImageButton = styled(ButtonBase)(({ theme }) => ({
position: 'relative',
height: 150,
[theme.breakpoints.down('sm')]: {
width: '100% !important', // Overrides inline-style
height: 100,
},
'&:hover, &.Mui-focusVisible': {
zIndex: 1,
'& .MuiImageBackdrop-root': {
opacity: 0.15,
},
'& .MuiImageMarked-root': {
opacity: 0,
},
'& .MuiTypography-root': {
border: '4px solid currentColor',
},
},
}));
const ImageSrc = styled('span')({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundSize: 'cover',
backgroundPosition: 'center 40%',
});
const ImageBackdrop = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: theme.palette.common.black,
opacity: 0.4,
transition: theme.transitions.create('opacity'),
}));
const ImageMarked = styled('span')(({ theme }) => ({
height: 3,
width: 18,
backgroundColor: theme.palette.common.white,
position: 'absolute',
bottom: -2,
left: 'calc(50% - 9px)',
transition: theme.transitions.create('opacity'),
}));
/*Image Button Styling Ends*/
const Search = styled('div')(({ theme }) => ({
position: 'relative',
borderRadius: theme.shape.borderRadius,
backgroundColor: alpha(theme.palette.common.white, 0.15),
'&:hover': {
backgroundColor: alpha(theme.palette.common.white, 0.25),
},
marginLeft: 0,
width: '100%',
[theme.breakpoints.up('sm')]: {
marginLeft: theme.spacing(1),
width: 'auto',
},
}));
const SearchIconWrapper = styled('div')(({ theme }) => ({
padding: theme.spacing(0, 2),
height: '100%',
position: 'absolute',
pointerEvents: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}));
const StyledInputBase = styled(InputBase)(({ theme }) => ({
color: 'inherit',
'& .MuiInputBase-input': {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
transition: theme.transitions.create('width'),
width: '100%',
[theme.breakpoints.up('sm')]: {
width: '12ch',
'&:focus': {
width: '20ch',
},
},
},
}));
const Header = () => {
const classes = useStyles();
return (<React.Fragment>
<AppBar position="sticky" className={classes.appBar}>
<Toolbar disableGutters>
{images.map((image) => (
<ImageButton
focusRipple
key={image.title}
style={{
width: image.width,
}}
>
<ImageSrc style={{
backgroundImage: `url(${image.url})`
}} />
<ImageBackdrop className="MuiImageBackdrop-root" />
<Image>
<Typography
component="span"
variant="subtitle1"
color="white"
fontWeight="bold"
sx={{
position: 'relative',
p: "7em",
pt: "2em",
pb: (theme) => `calc(${theme.spacing(1)} + 6px)`,
}}
>
{image.title}
<ImageMarked className="MuiImageMarked-root" />
</Typography>
</Image>
</ImageButton>
))}
<Button size="large" variant="contained" color="secondary"
startIcon={<AddIcon />}
sx={{
borderRadius: "40px", borderRadius: "40px",
width: "230px",
height: "130px",
marginLeft: "30px",
alignItem: "center",
}} >Add A recipe</Button>
<Button size="large" variant="contained" color="secondary" className={classes.button}>Meals for the Week</Button>
<Search>
<SearchIconWrapper>
<SearchIcon />
</SearchIconWrapper>
<StyledInputBase
placeholder="Search…"
inputProps={{ 'aria-label': 'search' }}
/>
</Search>
</Toolbar>
</AppBar>
</React.Fragment >
)
}
export default Header
Exactly, you need to add some configuration to the _document.tsx in order to make the styles work properly with the NextJS server side rendering feature. The reason behind this is that you need that some styles are injected in the DOM for you.
As you can see in the MUI docs, you can use the ServerStyleSheets to handle the server side rendering properly.
This is the code I have in my _document.tsx
import React from 'react';
import Document, { Html, Main, NextScript } from 'next/document';
import { ServerStyleSheets } from '#mui/styles';
export default class MyDocument extends Document {
render() {
return (
<Html>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
MyDocument.getInitialProps = async (ctx) => {
// Render app and page and get the context of the page with collected side effects.
const sheets = new ServerStyleSheets();
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => sheets.collect(<App {...props} />)
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
// Styles fragment is rendered after the app and page rendering finish.
styles: [...React.Children.toArray(initialProps.styles), sheets.getStyleElement()]
};
};
You can read more information about this in these Server rendering - MUI docs

angular ag-grid how to style the header

I am using ag-grid in my angular application and trying to export to excel. I want to style the header row in the excel. Can anyone help me how to achieve this? I tried the below but doesnt seems to be working.
this.excelStyles = [
{
id: 'smallFont',
font: {
fontName:'Calibri',
size: 9
}
},
{
id:'blueBackground',
interior: {
color: 'blue',
pattern: 'solid'
}
}
]
defaultColDef: {
cellClassRules: {
smallFont: (params) => true,
blueBackground: (params) => params.rowIndex == 0
}
}
Thanks
Seting the excelstyle with id 'header' as shown below will set style for the excel headers.
{
id:'header',
interior: {
color: '#002776',
pattern: 'solid'
},
font: {
color: '#ffffff',
fontName: 'Calibri',
size: 9,
bold: true
}
}

How to increase size of this font in Chart.js?

I need some help.I'm trying to increase font-size for this badges, and I have no idea how to do that. Maybe can you help me? I have tried before fontSize but doesn't affect the style.
Badges:
Here is my code:
<script>
new Chart(document.getElementById("doughnut-chart"), {
type: 'doughnut',
data: {
labels: {!!$labels->toJson()!!},
innerHeight: "50%",
datasets: [
{
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: {!!$values->toJson()!!},
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
layout: {
padding: {
left: 35,
right: 0,
top: 0,
bottom: 0
}
},
legend: {
display: true,
position: 'right',
labels: {
fontColor: "#000080",
boxWidth: 25,
fontSize: 25,
}
},
</script>

Powershell parse Html series to save it in a csv

I'm trying to scrape a website to keep track of my ranking in a Rocket League playlist over time automatically. The idea being that I'd grab the number corresponding to my playlist and put it in a csv for tacking purposes. I've been able to get the Html for the webpage but can't seem to parse it effectively for the number I'm after.
Here's how I've gathered the webpage info:
$tracker = Invoke-WebRequest -Uri
https://rocketleague.tracker.network/profile/steam/adammast12
$tracker.RawContent
Here's the section of the RawContent that is of interest to me:
<script type="text/javascript">
$('#playlist-tracking-rating').highcharts({
chart: {
type: 'line',
zoomType: 'xy'
},
title: {
text: 'Rating Progression'
},
xAxis: {
categories: ['Nov 05','Nov 08','Nov 10','Nov 11','Nov 12','Nov 13'],
type: 'date',
},
yAxis: {
title: {
text: 'Rating'
}
},
tooltip: {
enabled: true,
shared: true
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [
{ name: 'Un-Ranked', data: [1270,1270,1270,1270,1270,1251] },
{ name: 'Ranked Duel 1v1', data: [655,655,655,655,655,655] },
{ name: 'Ranked Doubles 2v2', data: [815,775,856,847,865,865] },
{ name: 'Ranked Solo Standard 3v3', data: [788,788,788,788,788,788] },
{ name: 'Ranked Standard 3v3', data: [994,994,994,994,994,994] },
{ name: 'Hoops', data: [556,556,556,556,525,525] },
{ name: 'Rumble', data: [651,741,703,703,704,704] },
{ name: 'Dropshot', data: [635,635,635,635,635,635] },
{ name: 'Snowday', data: [770,770] },
]
});
$('#playlist-tracking').highcharts({
chart: {
type: 'spline',
zoomType: 'xy'
},
title: {
text: 'Tier Over Time'
},
subtitle: {
text: ''
},
xAxis: {
categories: ['Nov 05','Nov 08','Nov 10','Nov 11','Nov 12','Nov 13'],
type: 'date',
labels: {
overflow: 'justify'
}
},
tooltip: {
enabled: true,
shared: true
},
yAxis: {
title: {
text: ''
},
labels: {
enabled: false
},
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null,
plotBands: [{
from: 0,
to: 0.99,
color: 'rgba(75, 75, 75, 0.1)',
label: {
text: 'Unranked',
style: {
color: '#606060'
}
}
}, {
from: 1,
to: 1.99,
color: 'rgba(227, 150, 68, 0.1',
label: {
text: 'Bronze I',
style: {
color: '#606060'
}
}
}, {
from: 2,
to: 2.99,
color: 'rgba(227, 150, 68, 0.1)',
label: {
text: 'Bronze II',
style: {
color: '#606060'
}
}
}, {
from: 3,
to: 3.99,
color: 'rgba(227, 150, 68, 0.1)',
label: {
text: 'Bronze III',
style: {
color: '#606060'
}
}
}, {
from: 4,
to: 4.99,
color: 'rgba(197, 197, 197, 0.1)',
label: {
text: 'Silver I',
style: {
color: '#606060'
}
}
}, {
from: 5,
to: 5.99,
color: 'rgba(197, 197, 197, 0.1)',
label: {
text: 'Silver II',
style: {
color: '#606060'
}
}
}, {
from: 6,
to: 6.99,
color: 'rgba(197, 197, 197, 0.1)',
label: {
text: 'Silver III',
style: {
color: '#606060'
}
}
}, {
from: 7,
to: 7.99,
color: 'rgba(206, 163, 32, 0.1)',
label: {
text: 'Gold I',
style: {
color: '#606060'
}
}
}, {
from: 8,
to: 8.99,
color: 'rgba(206, 163, 32, 0.1)',
label: {
text: 'Gold II',
style: {
color: '#606060'
}
}
}, {
from: 9,
to: 9.99,
color: 'rgba(206, 163, 32, 0.1)',
label: {
text: 'Gold III',
style: {
color: '#606060'
}
}
}, {
from: 10,
to: 10.99,
color: 'rgba(37, 161, 213, 0.1)',
label: {
text: 'Platinum I',
style: {
color: '#606060'
}
}
}, {
from: 11,
to: 11.99,
color: 'rgba(37, 161, 213, 0.1)',
label: {
text: 'Platinum II',
style: {
color: '#606060'
}
}
}, {
from: 12,
to: 12.99,
color: 'rgba(37, 161, 213, 0.1)',
label: {
text: 'Platinum III',
style: {
color: '#606060'
}
}
}, {
from: 13,
to: 13.99,
color: 'rgba(0, 79, 182, 0.1)',
label: {
text: 'Diamond I',
style: {
color: '#606060'
}
}
}, {
from: 14,
to: 14.99,
color: 'rgba(0, 79, 182, 0.1)',
label: {
text: 'Diamond II',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(0, 79, 182, 0.1)',
label: {
text: 'Diamond III',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(142, 89, 225, 0.1)',
label: {
text: 'Champion I',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(142, 89, 225, 0.1)',
label: {
text: 'Champion II',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(142, 89, 225, 0.1)',
label: {
text: 'Champion III',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(249, 135, 254, 0.1)',
label: {
text: 'Grand Champion',
style: {
color: '#606060'
}
}
}]
},
plotOptions: {
spline: {
lineWidth: 4,
states: {
hover: {
lineWidth: 5
}
},
marker: {
enabled: false
}
}
},
navigation: {
menuItemStyle: {
fontSize: '10px'
}
},
series: [
{ name: 'Ranked Duel 1v1', data: [0,0,0,0,0,0] },
{ name: 'Ranked Doubles 2v2', data: [11,11,12,12,12,12] },
{ name: 'Ranked Solo Standard 3v3', data: [0,0,0,0,0,0] },
{ name: 'Ranked Standard 3v3', data: [0,0,0,0,0,0] },
{ name: 'Hoops', data: [0,0,0,0,0,0] },
{ name: 'Rumble', data: [0,11,11,11,11,11] },
{ name: 'Dropshot', data: [10,10,10,10,10,10] },
{ name: 'Snowday', data: [12,12] },
]
});
I'd like to get the information out of the series related to the ranked playlists. For example, I need to be able to get the first value corresponding to "Ranked Duel 1v1" and "Ranked Doubles 2v2" etc. so I can save that number in a csv.
I've tried searching by string like this:
$data = $tracker.tostring() -split "[`r`n]" | select-string "Ranked Standard 3v3"
Which gives me this as a result:
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
{ name: 'Ranked Standard 3v3', data:
[994,994,994,994,994,994] },
{ name: 'Ranked Standard 3v3', data: [0,0,0,0,0,0] },
I'm not sure how to parse it from there though. Thanks for any help!
Here's a sample of how to just get the 'Un-tracked' section:
# result ArrayList
$results = New-Object System.Collections.ArrayList
# REST Get
$tracker = Invoke-WebRequest -Uri https://rocketleague.tracker.network/profile/steam/adammast12
# HTML data
# $tracker.RawContent
# split by carriage return + new line
# select the JSON with "name:" in it
$data = $tracker.tostring() -split "`r`n" | Select-String "name:"
# Un-Ranked data
$unranked = $data | Select-String "name: 'Un-Ranked'"
# Split at []'s
$unrankedSplit = $unranked.ToString().Split('[').Split(']')
# this yields a result like this:
# { name: 'Un-Ranked', data:
# 1270,1270,1270,1270,1270,1251
# },
#
# Split again at the second position on each comma, position [1]
# since PowerShell is zero-based indexing
$unrankedSplitChild = $unrankedSplit[1].Split(',')
# loop through each item with custom objects
foreach($item in $unrankedSplitChild)
{
# create a PSCustomObject and add to to the results
$results += [PSCustomObject]#{Category="Un-Ranked";Data=$item}
}
# throw the results to the console
$results | Format-Table -AutoSize

ReactNativeDisplay Json file in another format

rookie in RN, thanks in advance! I want to display a json file on a page.
This is the format of the json:
{
"prediction": [
{ "name":"egg", "value":"0.95" },
{ "name":"apple", "value":"0.02" },
{ "name":"peach", "value":"0.01" },
{ "name":"orange", "value":"0.01" },
{ "name":"fish", "value":"0.01" }
]
}
Assuming the Name of the json will be " /app/prediction.json ".
And the text input method I had on this page will be :
import { Tile, List, ListItem, Button } from 'react-native-elements';
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Dimensions,
View
} from 'react-native';
export default class ProjectOne extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.text}> Analysis </Text>
<Text> The object has " 95% possibility to be an egg, 40% to be an apple "</Text>
</View>
);
}
}
const styles = StyleSheet.create({
text: {
fontSize: 20,
fontWeight: 'bold',
},
container: {
height: 275,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
height: Dimensions.get('window').height,
width: Dimensions.get('window').width
},
capture: {
flex: 0,
backgroundColor: 'black',
borderRadius: 5,
color: '#ffffff',
padding: 10,
margin: 40
}
});
AppRegistry.registerComponent('ProjectOne', () => ProjectOne);
Is there any way that I can fetch the json file, and then, display the json content into that text field on this page?
You can do it by using require('./app/prediction.json') then convert it to string or format if needed