Skip to content

Commit 7dcb2be

Browse files
update HexTextField to accept optional label or placeholder
1 parent f2ee97d commit 7dcb2be

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

README.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
### Jetpack Compose Color Picker Bundle
1+
# Jetpack Compose Color Picker Bundle
22

33
Bundle of Stylish customizable Color pickers, selectors, colorful sliders written with Jetpack
44
Compose enables users to choose from HSL, HSV or RGB color models to pick Solid colors or gradients.
55
With colorful Sliders, panels, hex and color displays and various elements to create customized
66
pickers based on preference.
77

8-
There are 10(for now) different color pickers and 3 different color+gradient pickers available to
9-
choose from to use as Composables or inside dialogs that are available in demos.
10-
11-
8+
There are 12, as of current version, different color pickers and 3 different color+gradient pickers
9+
available to choose from to use as Composables or inside dialogs that are available in demos.
1210

1311
https://user-images.githubusercontent.com/35650605/161702454-34b0cf00-8496-4060-bfe1-bea9d1bf754d.mp4
1412

15-
16-
1713
Inspired
1814
by [mchome's flutter_colorpicker for Flutter](https://github.com/mchome/flutter_colorpicker)
1915

20-
### Color Pickers
16+
## Color Pickers
2117

2218
There are various selection of default color pickers and with selectors sliders, and hex displays
2319
it's possible to create new ones either.
@@ -30,12 +26,11 @@ it's possible to create new ones either.
3026
| ----------|-----------| -----------| -----------|
3127
| <img src="./screenshots/colorpicker/cp_rect_saturation_value_hsv.png"/> | <img src="./screenshots/colorpicker/cp_rect_saturation_lightness_hsl.png"/> | <img src="./screenshots/colorpicker/cp_circle_hue_saturation_hsv.png"/> | <img src="./screenshots/colorpicker/cp_ring_rect_hex_hsv.png"/> |
3228

33-
| Hue-Saturation HSV | Hue-Value HSV | Hue-Saturation HSL | Hue-Lightness HSL |
29+
| HS HSV | HL HSV | HS HSL | HL HSL |
3430
| ----------|-----------| -----------| -----------|
3531
| <img src="./screenshots/colorpicker/cp_rect_hue_saturation_hsv.png"/> | <img src="./screenshots/colorpicker/cp_rect_hue_value_hsv.png"/> | <img src="./screenshots/colorpicker/cp_rect_hue_saturation_hsl.png"/> | <img src="./screenshots/colorpicker/cp_rect_hue_lightness_hsl.png"/> |
3632

37-
38-
#### Implementation Hue Ring-Diamond HSL, Hue- Ring-Rect HSL,Hue Ring-Rect HSV
33+
### Implementation Hue Ring-Diamond HSL and ones with Ring Selectors
3934

4035
```
4136
ColorPickerRingRectHSL(
@@ -66,7 +61,7 @@ color can be set using `CompositeSliderPanel` which contains sliders for each co
6661
* **onColorChange** callback that is triggered when `Color` is changed
6762
using `SelectorRingHue` `SelectorDiamondSaturationLightnessHSL` or `CompositeSliderPanel`
6863

69-
#### Implementation for other Color Pickers
64+
### Implementation for other Color Pickers
7065

7166
```
7267
ColorPickerCircleValueHSV(
@@ -81,7 +76,7 @@ ColorPickerCircleValueHSV(
8176
* **initialColor** color that is passed to this picker initially.
8277
* **onColorChange** callback that is triggered when `Color` is changed
8378

84-
### Gradient Color Pickers
79+
## Gradient Color Pickers
8580

8681
| Hue Ring-Diamond HSL | Hue Ring-Diamond HSL2 | Hue- Ring-Rect HSL | Hue Ring-Rect HSV|
8782
| ----------|-----------| -----------| -----------|
@@ -175,7 +170,7 @@ data class BrushColor(
175170
}
176171
```
177172

178-
### Demos
173+
## Demos
179174

180175
* `SaturationSelectorDemo` different type of Hue/Saturation/Value/Lightness Selectors
181176
* `GradientSelection` select gradient with varying properties such as tile mode, angle, size, or
@@ -189,7 +184,7 @@ data class BrushColor(
189184
| ----------|-----------|-----------| -----------| -----------|
190185
| <img src="./screenshots/saturation.gif"/> | <img src="./screenshots/gradient_selection.gif"/> | <img src="./screenshots/gradient_angle.gif"/> | <img src="./screenshots/hsv_hsl_gradient.gif"/> | <img src="./screenshots/colorful_sliders.gif"/> |
191186

192-
### Completed:
187+
## Completed:
193188

194189
- [x] Add Hue Picker Wheel for selecting Hue
195190
- [x] Add Saturation Rectangle for selecting Saturation and Lightness

colorpicker/src/main/java/com/smarttoolfactory/colorpicker/widget/HexTextField.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ import com.smarttoolfactory.colorpicker.util.hexWithAlphaRegex
2626
/**
2727
* [TextField] that displays color in hex representation either with #RRGGBB or #AARRGGBB
2828
* depending on [useAlpha] flag.
29-
* @param colors that are used by default [TextField] to set background and many other default
30-
* properties.
31-
* @param textStyle style for [Text] of [TextField].
29+
*
30+
* @param colors [TextFieldColors] that will be used to resolve color of the text and content
31+
* (including label, placeholder, leading and trailing icons, border) for this text field in
32+
* different states. See [TextFieldDefaults.outlinedTextFieldColors]
33+
* @param textStyle the style to be applied to the input text. The default [textStyle] uses the
34+
* [LocalTextStyle] defined by the theme
35+
* @param label the optional label to be displayed inside the text field container. The default
36+
* text style for internal [Text] is [Typography.caption] when the text field is in focus and
37+
* [Typography.subtitle1] when the text field is not in focus
38+
* @param placeholder the optional placeholder to be displayed when the text field is in focus and
39+
* the input text is empty. The default text style for internal [Text] is [Typography.subtitle1]
3240
* @param shape of this [TextField].
3341
* @param hexString string in hex format.
3442
* @param useAlpha when set to true returns colors in #AARRGGBB format.
@@ -47,6 +55,12 @@ fun HexTextField(
4755
focusedIndicatorColor = Color.Transparent,
4856
unfocusedIndicatorColor = Color.Transparent
4957
),
58+
label: @Composable () -> Unit = {
59+
Text("Hex", color = Grey400)
60+
},
61+
placeholder: @Composable () -> Unit = {
62+
Text("Enter a color", fontSize = textStyle.fontSize)
63+
},
5064
shape: Shape = RoundedCornerShape(25),
5165
useAlpha: Boolean = false,
5266
onTextChange: (String) -> Unit,
@@ -68,8 +82,8 @@ fun HexTextField(
6882
textStyle = textStyle,
6983
colors = colors,
7084
shape = shape,
71-
label = { Text("Hex", color = Grey400) },
72-
placeholder = { Text("Enter a color", fontSize = textStyle.fontSize) },
85+
label = label,
86+
placeholder = placeholder,
7387
value = hexString.removePrefix("#"),
7488
onValueChange = {
7589

@@ -82,8 +96,7 @@ fun HexTextField(
8296
}
8397

8498
if (validHex) {
85-
onTextChange(it)
86-
99+
onTextChange("#$it")
87100
// Hex String with 6 or 8 chars matches a Color
88101
if (hex.matches(it)) {
89102
onColorChange(hexToColor(it))

0 commit comments

Comments
 (0)