@mui/material#ToggleButton JavaScript Examples

The following examples show how to use @mui/material#ToggleButton. 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: ForecastToggle.js    From SimpleWeather with MIT License 5 votes vote down vote up
ForecastToggle = (props) => {
    if (!localStorage.getItem('forecastScale')) {
        localStorage.setItem('forecastScale', 'threeDay');
    }
    const [value, setValue] = useState(localStorage.getItem('forecastScale'));
    return (
        <div className='forecast-toggle-wrapper'>
            <ToggleButtonGroup
                color='secondary'
                value={value}
                exclusive
                sx={{
                    '& .MuiToggleButton-root': {
                        backgroundColor: 'transparent',
                        borderColor: '#F9FBFF',
                        color: '#2d81ff',
                        textTransform: 'capitalize',
                        '&.Mui-selected': {
                            backgroundColor: '#6BA6FF',
                            color: '#ffffff',
                        },
                        '&.Mui-selected:hover': {
                            backgroundColor: '#5096ff',
                            color: '#ffffff',
                        }
                    },
                    height: '24px',
                }}
                fullWidth={true}
                className='forecast-toggle'
                onChange={() => {
                    if (value === 'threeDay') {
                        setValue('hourly')
                        props.changeForecastMod('hourly');
                        localStorage.setItem('forecastScale', 'hourly')
                    } else {
                        setValue('threeDay')
                        props.changeForecastMod('threeDay')
                        localStorage.setItem('forecastScale', 'threeDay')
                    }
                }}
            >
                <ToggleButton value='hourly' sx={{borderRadius: '20px 0 0 20px'}}>
                    Hourly
                </ToggleButton>
                <ToggleButton value='threeDay' sx={{borderRadius: '0 20px 20px 0'}}>
                    Three-day
                </ToggleButton>
            </ToggleButtonGroup>
        </div>
    );
}
Example #2
Source File: TempScaleToggle.js    From SimpleWeather with MIT License 5 votes vote down vote up
TempScaleToggle = (props) => {
    if (!localStorage.getItem('tempScale')) {
        localStorage.setItem('tempScale', 'celsius');
    }
    const [value, setValue] = useState(localStorage.getItem('tempScale'));
    return (
        <ToggleButtonGroup
            color='secondary'
            value={value}
            exclusive
            fullWidth={true}
            sx={{
                '& .MuiToggleButton-root': {
                    backgroundColor: 'transparent',
                    borderColor: '#F9FBFF',
                    color: '#2d81ff',
                    textTransform: 'capitalize',
                    '&.Mui-selected': {
                        backgroundColor: '#6BA6FF',
                        color: '#ffffff',
                    },
                    '&.Mui-selected:hover': {
                        backgroundColor: '#5096ff',
                        color: '#ffffff',
                    }
                },
                height: '24px',
            }}
            onChange={() => {
                if (value === 'celsius') {
                    setValue('fahrenheit')
                    props.changeTempScale('fahrenheit');
                    localStorage.setItem('tempScale', 'fahrenheit')
                } else {
                    setValue('celsius')
                    props.changeTempScale('celsius')
                    localStorage.setItem('tempScale', 'celsius')
                }
            }}
        >
            <ToggleButton value='fahrenheit' sx={{borderRadius: '20px 0 0 20px'}}>
                Fahrenheit
            </ToggleButton>
            <ToggleButton value='celsius' sx={{borderRadius: '0 20px 20px 0'}}>
                Celsius
            </ToggleButton>
        </ToggleButtonGroup>
    );
}