Open naser09 opened 2 months ago
one more thing . with the default file picker I wasn't able to do what I wanted because the file is plain text and it got encoded to base64 . so for picking different file I modified BSFilePicker to
changed the on click function for file pick . . document.loadTextFromDisk( accept = accept, onLoad = { onFileSelected(filename, it) placeholderText = filename } )
here is the complete code for text picker .
@Composable
fun BSTextFilePicker(
modifier: Modifier = Modifier,
id: String? = null,
label: String? = null,
placeholder: String = "No file selected.",
size: InputSize = InputSize.Default,
disabled: Boolean = false,
accept: String = "plain/text, .txt",
onFileSelected: (String, String) -> Unit
) {
val randomId = remember {
id ?: UniqueIdGenerator.generateUniqueId("fileinput")
}
var placeholderText by remember { mutableStateOf(placeholder) }
Div(attrs = modifier.toAttrs()) {
if(label != null) {
Label(
attrs = Modifier
.classNames("form-label")
.toAttrs(),
forId = randomId
)
{
Text(value = label)
}
}
Row(
modifier = Modifier
.id(randomId)
.thenIf(
condition = disabled,
// TODO: Will this color get used anywhere? Should we extract it into a constant?
other = Modifier.backgroundColor(Color.rgb(0xFAFAFA))
)
.border(
width = 1.px,
style = LineStyle.Solid,
color = rgba(r = 206, g = 212, b = 218, a = 1)
)
.padding(all = 0.px)
.onClick {
if (!disabled) {
document.loadTextFromDisk(
accept = accept,
onLoad = {
onFileSelected(filename, it)
placeholderText = filename
}
)
}
}
.overflow(Overflow.Hidden)
.textOverflow(TextOverflow.Ellipsis)
.thenIf(
condition = size != InputSize.Default,
other = Modifier.classNames(size.value)
)
.borderRadius(0.375.cssRem),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start
) {
BSButton(
modifier = Modifier
.margin(all = 0.px)
.borderRadius(topRight = 0.px, bottomRight = 0.px),
text = "Browse...",
variant = ButtonVariant.Light,
size = when (size) {
InputSize.Default -> {
ButtonSize.Default
}
InputSize.Small -> {
ButtonSize.Small
}
InputSize.Large -> {
ButtonSize.Large
}
},
disabled = disabled,
onClick = {}
)
SpanText(
modifier = Modifier
.thenIf(
condition = disabled,
other = Modifier.classNames("text-muted")
)
.margin(leftRight = 12.px),
text = placeholderText
)
}
}
}```
as an android developer i was missing Card component while using this library . so made my own . i was going to do a pull request but as a solo (self taught) developer i am bad at collaboration . so here is the code . please add the component if you think its necessary or usable . or modify it to your liking . maybe its need some more effect like hover effect . but in my case I am using simple card to show my data .