Spaces:
Runtime error
Runtime error
File size: 3,089 Bytes
8fd7a1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import PropTypes from 'prop-types';
import React from 'react';
import {FormattedMessage} from 'react-intl';
import styles from './custom-procedures.css';
// Scratch block category colors
const SCRATCH_COLORS = [
{ name: 'Motion', color: '#4C97FF' },
{ name: 'Looks', color: '#9966FF' },
{ name: 'Sound', color: '#CF63CF' },
{ name: 'Events', color: '#FFBF00' },
{ name: 'Control', color: '#FFAB19' },
{ name: 'Sensing', color: '#5CB1D6' },
{ name: 'Operators', color: '#59C059' },
{ name: 'Variables', color: '#FF8C1A' },
{ name: 'Lists', color: '#FF661A' },
{ name: 'My Blocks', color: '#FF6680' },
{ name: 'Pen', color: '#0fBD8C' }
];
const ColorPicker = props => {
const handlePresetColorClick = (presetColor) => {
// Create a synthetic event to match the expected interface
const syntheticEvent = {
target: {
value: presetColor
}
};
props.onColorChange(syntheticEvent);
};
return (
<div className={styles.colorPickerRow}>
<div className={styles.colorPickerLabel}>
<FormattedMessage
defaultMessage="Block color"
description="Label for block color picker in custom procedures"
id="gui.customProcedures.blockColor"
/>
</div>
{/* Color Grid */}
<div className={styles.colorGrid}>
{SCRATCH_COLORS.map((colorInfo, index) => (
<div
key={index}
className={`${styles.colorGridItem} ${props.color === colorInfo.color ? styles.colorGridItemSelected : ''}`}
style={{ backgroundColor: colorInfo.color }}
onClick={() => handlePresetColorClick(colorInfo.color)}
title={colorInfo.name}
role="button"
tabIndex="0"
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handlePresetColorClick(colorInfo.color);
}
}}
/>
))}
</div>
{/* Custom Color Input */}
<div className={styles.colorPickerContainer}>
<input
className={styles.colorPickerInput}
type="color"
value={props.color}
onChange={props.onColorChange}
/>
<div
className={styles.colorPreview}
style={{backgroundColor: props.color}}
/>
<span className={styles.colorValue}>{props.color}</span>
</div>
</div>
);
};
ColorPicker.propTypes = {
color: PropTypes.string.isRequired,
onColorChange: PropTypes.func.isRequired
};
export default ColorPicker;
|