lemmy-ui/src/shared/components/common/comment-sort-select.tsx

70 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Component, linkEvent } from "inferno";
import { CommentSortType } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { randomStr, relTags, sortingHelpUrl } from "../../utils";
import { Icon } from "./icon";
interface CommentSortSelectProps {
sort: CommentSortType;
onChange?(val: CommentSortType): any;
}
interface CommentSortSelectState {
sort: CommentSortType;
}
export class CommentSortSelect extends Component<
CommentSortSelectProps,
CommentSortSelectState
> {
private id = `sort-select-${randomStr()}`;
state: CommentSortSelectState = {
sort: this.props.sort,
};
constructor(props: any, context: any) {
super(props, context);
}
static getDerivedStateFromProps(props: any): CommentSortSelectState {
return {
sort: props.sort,
};
}
render() {
return (
<>
<select
id={this.id}
name={this.id}
value={this.state.sort}
onChange={linkEvent(this, this.handleSortChange)}
feat: Bootstrap 5 (#1378) * feat: Use Bootstrap 5; remove Bootstrap 4 * feat: Add link decoration override global var * fix: Change sr-only to visually-hidden * fix: Fix missing toggle button classes * fix: Use darker green to pass 3:1 contrast and allow foreground color generation * fix: Replace all mr- and ml- classes with me- (end) and ms- (start) classes * fix: Replace all pr- and pl- classes with pe- (end) and ps- (start) classes * fix: Replace custom-select with form-select d-inline-block * fix: Change max-width to Bootstrap 4's max-width * fix: Fix badge colors * fix: Replace deprecated btn-block class with d-block * fix: Temporary fix for missing btn-block styles * fix: Fix margin-left auto and margin-right auto * fix: Fix default border color * fix: Fix some button widths * fix: Fix form row margins * fix: Remove theme color maps; no longer necessary in Bootstrap 5 * fix: Remove unused gray * test commit * fix: Fix deprecated input-group-append usage * fix: Add missing col-form-label classes * fix: Fix some column widths * fix: Fix language dropdown style regression * fix: Fix toast background color * fix: Fix missing colors in red themes * fix: Fix default radio button appearance for toggles * fix: Fix missing margin in search form * fix: Fix search form widths * fix: Fix rate limit form columns * fix: Fix search filters layout * fix: Fix weird table background issue; re-compile from main updates * fix: Fix modlog filter layout * fix: Fix some horizontal margins * fix: Fix incorrect usage of input-group * chore: Empty commit to re-trigger Woodpecker job * fix: Fix incorrect Bootstrap 5 padding class * fix: Tighten up the home filter bars for the hell of it * fix: Fix home filter bar gap --------- Co-authored-by: SleeplessOne1917 <abias1122@gmail.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2023-06-20 12:01:29 +00:00
className="form-select d-inline-block w-auto me-2 mb-2"
aria-label={i18n.t("sort_type")}
>
<option disabled aria-hidden="true">
{i18n.t("sort_type")}
</option>
<option value={"Hot"}>{i18n.t("hot")}</option>,
<option value={"Top"}>{i18n.t("top")}</option>,
<option value={"New"}>{i18n.t("new")}</option>
<option value={"Old"}>{i18n.t("old")}</option>
</select>
<a
className="text-muted"
href={sortingHelpUrl}
rel={relTags}
title={i18n.t("sorting_help")}
>
<Icon icon="help-circle" classes="icon-inline" />
</a>
</>
);
}
handleSortChange(i: CommentSortSelect, event: any) {
i.props.onChange?.(event.target.value);
}
}